def best
import bend-kit-router@0.2.0.0/router.bend as Routerimport Base
316# ponytail: lookup scans prepared paths in O(routes × segments); use a trie if measured dispatch cost warrants it.
317def best(~A: Data, paths: List<&2, Path<A>>, +segments: List<&2, String>, acc: Maybe<&2, Path<A>>) -> Maybe<&2, Path<A>>:
318 match paths:
319 case Nil{}:
320 acc
321 case Path{+ss, handlers, groups, allowed} <> t:
322 best(~A, t, segments, best.step(~A, matches(ss, segments), Path{ss, handlers, groups, allowed}, acc))