Cli.wrap_words: def of cli@0.2.0.0 Import: import cli@0.2.0.0/cli.bend as Cli Lines 1019-1032 of cli@0.2.0.0/cli.bend: https://jend.leeeet.dev/read.txt?path=cli@0.2.0.0/cli.bend&start_line=1019&end_line=1032 import Base def wrap_words(words: List<&2, String>, state: WrapState) -> String: match words state: case Nil{} WrapState{indent, cols, line, started, done}: Bool.pick(String, started, String.join(List.reverse(&2, String, line <> done), "\n"), "") case +word <> rest WrapState{+indent, +cols, +line, +started, +done}: +candidate = Bool.pick(String, started, String.append(line, String.append(" ", word)), String.append(indent, word)) fits = Bool.or(Bool.not(started), Nat.is_le(width(strip(candidate)), cols)) next = Bool.pick(WrapState, fits, WrapState{indent, cols, candidate, True{}, done}, WrapState{indent, cols, String.append(indent, word), True{}, line <> done}) wrap_words(rest, next) Uses (13): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.not https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.or https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List.reverse https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.is_le https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.join https://jend.leeeet.dev/definition.txt?path=cli@0.2.0.0/cli.bend&name=WrapState https://jend.leeeet.dev/definition.txt?path=cli@0.2.0.0/cli.bend&name=strip https://jend.leeeet.dev/definition.txt?path=cli@0.2.0.0/cli.bend&name=width