( self: RequestBlock.RequestBlock, reducer: RequestBlock.RequestBlock.Reducer<Z> )
| 100 | * @internal |
| 101 | */ |
| 102 | export const reduce = <Z>( |
| 103 | self: RequestBlock.RequestBlock, |
| 104 | reducer: RequestBlock.RequestBlock.Reducer<Z> |
| 105 | ): Z => { |
| 106 | let input: List.List<RequestBlock.RequestBlock> = List.of(self) |
| 107 | let output = List.empty<Either.Either<Z, BlockedRequestsCase>>() |
| 108 | while (List.isCons(input)) { |
| 109 | const current: RequestBlock.RequestBlock = input.head |
| 110 | switch (current._tag) { |
| 111 | case "Empty": { |
| 112 | output = List.cons(Either.right(reducer.emptyCase()), output) |
| 113 | input = input.tail |
| 114 | break |
| 115 | } |
| 116 | case "Par": { |
| 117 | output = List.cons(Either.left({ _tag: "ParCase" }), output) |
| 118 | input = List.cons(current.left, List.cons(current.right, input.tail)) |
| 119 | break |
| 120 | } |
| 121 | case "Seq": { |
| 122 | output = List.cons(Either.left({ _tag: "SeqCase" }), output) |
| 123 | input = List.cons(current.left, List.cons(current.right, input.tail)) |
| 124 | break |
| 125 | } |
| 126 | case "Single": { |
| 127 | const result = reducer.singleCase(current.dataSource, current.blockedRequest) |
| 128 | output = List.cons(Either.right(result), output) |
| 129 | input = input.tail |
| 130 | break |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | const result = List.reduce(output, List.empty<Z>(), (acc, current) => { |
| 135 | switch (current._tag) { |
| 136 | case "Left": { |
| 137 | const left = List.unsafeHead(acc) |
| 138 | const right = List.unsafeHead(List.unsafeTail(acc)) |
| 139 | const tail = List.unsafeTail(List.unsafeTail(acc)) |
| 140 | switch (current.left._tag) { |
| 141 | case "ParCase": { |
| 142 | return List.cons(reducer.parCase(left, right), tail) |
| 143 | } |
| 144 | case "SeqCase": { |
| 145 | return List.cons(reducer.seqCase(left, right), tail) |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | case "Right": { |
| 150 | return List.cons(current.right, acc) |
| 151 | } |
| 152 | } |
| 153 | }) |
| 154 | if (List.isNil(result)) { |
| 155 | throw new Error( |
| 156 | "BUG: BlockedRequests.reduce - please report an issue at https://github.com/Effect-TS/effect/issues" |
| 157 | ) |
| 158 | } |
| 159 | return result.head |
no test coverage detected