Util.map_halves.go: def of unified-nsga-iii@0.2.2.0 Import: import unified-nsga-iii@0.2.2.0/util.bend as Util Lines 275-300 of unified-nsga-iii@0.2.2.0/util.bend: https://jend.leeeet.dev/read.txt?path=unified-nsga-iii@0.2.2.0/util.bend&start_line=275&end_line=300 import Base # Balanced fork-join map. Singleton / empty stay sequential. Fuel 0 is a # total fallback (public callers pass |xs|). `~f` is a closed top-level. # Mid take/drop is inlined: a computed pair cannot be matched. def map_halves.go( ~A: Data, ~B: Data, ~C: Data, ~f: @+c:C -> @+x:A -> B, +ctx: C, +fuel: Nat, xs: List<&2, A> ) -> List<&2, B>: match fuel xs: case 0n Nil{}: Nil{} case 0n h <> t: f(ctx, h) <> map_halves.go(~A, ~B, ~C, ~f, ctx, 0n, t) case 1n+p Nil{}: Nil{} case 1n+p h <> Nil{}: f(ctx, h) <> Nil{} case 1n+p h <> t: +all = {h <> t : List<&2, A>} +mid = Nat.div(list_len(A, all), 2n) a b = map_halves.go(~A, ~B, ~C, ~f, ctx, p, List.take(&2, A, all, mid)) map_halves.go(~A, ~B, ~C, ~f, ctx, p, List.drop(&2, A, all, mid)) List.append(&2, B, a, b) Uses (7): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.drop https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.take https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.div https://jend.leeeet.dev/definition.txt?path=unified-nsga-iii@0.2.2.0/util.bend&name=list_len