Router.insert: def of bend-kit-router@0.2.0.0 Import: import bend-kit-router@0.2.0.0/router.bend as Router Lines 219-228 of bend-kit-router@0.2.0.0/router.bend: https://jend.leeeet.dev/read.txt?path=bend-kit-router@0.2.0.0/router.bend&start_line=219&end_line=228 import Base # ponytail: preparation merges shapes in O(routes²); replace with a shape index if construction becomes a bottleneck. def insert(~A: Data, paths: List<&2, Path>, +entry: Handler, +groups: List<&2, U32>) -> Result<&2, &2, Error, List<&2, Path>>: match paths: case Nil{}: Handler{method, pattern, +ss, action} = entry Done{[Path{ss, [Handler{method, pattern, ss, action}], groups, ""}]} case Path{+ss, +handlers, +old_groups, +allow} <> +t: Handler{+method, +pattern, +es, +action} = entry candidate = {Handler{method, pattern, es, action} : Handler} insert.branch(~A, shape(ss, es), ss, handlers, old_groups, allow, t, candidate, groups, u => insert(~A, t, Handler{method, pattern, es, action}, groups)) Uses (8): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/router.bend&name=Error https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/router.bend&name=Handler https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/router.bend&name=Path https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/router.bend&name=insert.branch https://jend.leeeet.dev/definition.txt?path=bend-kit-router@0.2.0.0/router.bend&name=shape