def leads

bend-lint-rules@0.2.0.0 · performance/deep_call_in_fork.bend:131

import bend-lint-rules@0.2.0.0/performance/deep_call_in_fork.bend as DeepCallInFork
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint

131# Whether a let leads to a fork: it is one (it binds `many` names), or it binds one (`one`), and the last of `nodes`,
132# the rest of its block, is a let that leads to one. The values of these lets are what a fork runs, or what runs just
133# before it.
134def leads(nodes: List<&2, Lint.Node>, many: Bool, one: Bool) -> Bool:
135  match nodes many one:
136    case _ True{} _:
137      True{}
138    case _ False{} False{}:
139      False{}
140    case Con{Lint.Node{Lint.Destructure{q}, n, s, +kids, f}, Nil{}} False{} True{}:
141      +count = binders(kids, 0n)
142      leads(kids, Nat.is_gt(count, 1n), Nat.is_eq(count, 1n))
143    case Con{x, Nil{}} False{} True{}:
144      False{}
145    case Con{x, rest} False{} True{}:
146      leads(rest, False{}, True{})
147    case Nil{} False{} True{}:
148      False{}

Uses (7)

Used by (1)