( s: S, cost: number, dirty: boolean, max: number, costFn: (s: S, input: In) => number, decompose: (input: In) => Chunk.Chunk<In>, f: (s: S, input: In) => S )
| 1134 | |
| 1135 | /** @internal */ |
| 1136 | const foldWeightedDecomposeLoop = <S, In>( |
| 1137 | s: S, |
| 1138 | cost: number, |
| 1139 | dirty: boolean, |
| 1140 | max: number, |
| 1141 | costFn: (s: S, input: In) => number, |
| 1142 | decompose: (input: In) => Chunk.Chunk<In>, |
| 1143 | f: (s: S, input: In) => S |
| 1144 | ): Channel.Channel<Chunk.Chunk<In>, Chunk.Chunk<In>, never, never, S, unknown> => |
| 1145 | core.readWith({ |
| 1146 | onInput: (input: Chunk.Chunk<In>) => { |
| 1147 | const [nextS, nextCost, nextDirty, leftovers] = foldWeightedDecomposeFold( |
| 1148 | input, |
| 1149 | s, |
| 1150 | cost, |
| 1151 | dirty, |
| 1152 | max, |
| 1153 | costFn, |
| 1154 | decompose, |
| 1155 | f |
| 1156 | ) |
| 1157 | if (Chunk.isNonEmpty(leftovers)) { |
| 1158 | return pipe(core.write(leftovers), channel.zipRight(core.succeedNow(nextS))) |
| 1159 | } |
| 1160 | if (cost > max) { |
| 1161 | return core.succeedNow(nextS) |
| 1162 | } |
| 1163 | return foldWeightedDecomposeLoop(nextS, nextCost, nextDirty, max, costFn, decompose, f) |
| 1164 | }, |
| 1165 | onFailure: core.fail, |
| 1166 | onDone: () => core.succeedNow(s) |
| 1167 | }) |
| 1168 | |
| 1169 | /** @internal */ |
| 1170 | const foldWeightedDecomposeFold = <In, S>( |
no test coverage detected