def eagerly

bend-lint-rules@0.2.0.0 · performance/eager_branch.bend:66

import bend-lint-rules@0.2.0.0/performance/eager_branch.bend as EagerBranch
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint

66# The eager value a call below `path` is in, if one is above it and no lambda comes between. `found` stops the walk
67# once one is found.
68def eagerly(path: List<&2, Lint.Above>, found: Maybe<&2, Eager>) -> Maybe<&2, Eager>:
69  match path found:
70    case _ Some{e}:
71      Some{e}
72    case Con{Lint.Above{Lint.Node{Lint.Application{}, n, s, +kids, f}, +at}, rest} None{}:
73      eagerly(rest, Eager.of(eager(kids, at), List.get(&2, Lint.Node, kids, U32.to_nat(at))))
74    case Con{Lint.Above{Lint.Node{Lint.Lambda{b, q}, n, s, k, f}, at}, rest} None{}:
75      None{}
76    case Con{Lint.Above{Lint.Node{Lint.Body{}, n, s, k, f}, at}, rest} None{}:
77      None{}
78    case Con{a, rest} None{}:
79      eagerly(rest, None{})
80    case Nil{} None{}:
81      None{}

Uses (10)

Used by (1)