MCPcopy
hub / github.com/Effect-TS/effect / unionLoop

Function unionLoop

packages/effect/src/internal/schedule/intervals.ts:61–117  ·  view source on GitHub ↗
(
  _self: Chunk.Chunk<Interval.Interval>,
  _that: Chunk.Chunk<Interval.Interval>,
  _interval: Interval.Interval,
  _acc: Chunk.Chunk<Interval.Interval>
)

Source from the content-addressed store, hash-verified

59
60/** @internal */
61const unionLoop = (
62 _self: Chunk.Chunk<Interval.Interval>,
63 _that: Chunk.Chunk<Interval.Interval>,
64 _interval: Interval.Interval,
65 _acc: Chunk.Chunk<Interval.Interval>
66): Intervals.Intervals => {
67 let self = _self
68 let that = _that
69 let interval = _interval
70 let acc = _acc
71 while (Chunk.isNonEmpty(self) || Chunk.isNonEmpty(that)) {
72 if (!Chunk.isNonEmpty(self) && Chunk.isNonEmpty(that)) {
73 if (interval.endMillis < Chunk.headNonEmpty(that).startMillis) {
74 acc = pipe(acc, Chunk.prepend(interval))
75 interval = Chunk.headNonEmpty(that)
76 that = Chunk.tailNonEmpty(that)
77 self = Chunk.empty()
78 } else {
79 interval = Interval.make(interval.startMillis, Chunk.headNonEmpty(that).endMillis)
80 that = Chunk.tailNonEmpty(that)
81 self = Chunk.empty()
82 }
83 } else if (Chunk.isNonEmpty(self) && Chunk.isEmpty(that)) {
84 if (interval.endMillis < Chunk.headNonEmpty(self).startMillis) {
85 acc = pipe(acc, Chunk.prepend(interval))
86 interval = Chunk.headNonEmpty(self)
87 that = Chunk.empty()
88 self = Chunk.tailNonEmpty(self)
89 } else {
90 interval = Interval.make(interval.startMillis, Chunk.headNonEmpty(self).endMillis)
91 that = Chunk.empty()
92 self = Chunk.tailNonEmpty(self)
93 }
94 } else if (Chunk.isNonEmpty(self) && Chunk.isNonEmpty(that)) {
95 if (Chunk.headNonEmpty(self).startMillis < Chunk.headNonEmpty(that).startMillis) {
96 if (interval.endMillis < Chunk.headNonEmpty(self).startMillis) {
97 acc = pipe(acc, Chunk.prepend(interval))
98 interval = Chunk.headNonEmpty(self)
99 self = Chunk.tailNonEmpty(self)
100 } else {
101 interval = Interval.make(interval.startMillis, Chunk.headNonEmpty(self).endMillis)
102 self = Chunk.tailNonEmpty(self)
103 }
104 } else if (interval.endMillis < Chunk.headNonEmpty(that).startMillis) {
105 acc = pipe(acc, Chunk.prepend(interval))
106 interval = Chunk.headNonEmpty(that)
107 that = Chunk.tailNonEmpty(that)
108 } else {
109 interval = Interval.make(interval.startMillis, Chunk.headNonEmpty(that).endMillis)
110 that = Chunk.tailNonEmpty(that)
111 }
112 } else {
113 throw new Error(getBugErrorMessage("Intervals.unionLoop"))
114 }
115 }
116 return make(pipe(acc, Chunk.prepend(interval), Chunk.reverse))
117}
118

Callers 1

intervals.tsFile · 0.85

Calls 5

getBugErrorMessageFunction · 0.85
makeFunction · 0.70
makeMethod · 0.65
isEmptyMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected