def is_guarded
bend-lint-rules@0.2.0.0 · performance/repeated_call.bend:72
import bend-lint-rules@0.2.0.0/performance/repeated_call.bend as RepeatedCall
import Base
import bend-lint-api@0.2.0.0/linter/lint.bend as Lint
import bend-lint-rules@0.2.0.0/performance/deep_call_in_fork.bend as Deep
import bend-lint-rules@0.2.0.0/performance/missed_fork.bend as Fork
72
73
74def is_guarded(path: List<&2, Lint.Above>, found: Bool) -> Bool:
75 match path found:
76 case _ True{}:
77 True{}
78 case Nil{} False{}:
79 False{}
80 case Con{Lint.Above{Lint.Node{Lint.Lambda{b, q}, n, s, k, f}, at}, rest} False{}:
81 True{}
82 case Con{Lint.Above{Lint.Node{Lint.Application{}, n, s, +kids, f}, at}, rest} False{}:
83 is_guarded(rest, Fork.is_choice(kids))
84 case Con{Lint.Above{Lint.Node{Lint.Destructure{q}, n, s, +kids, f}, at}, rest} False{}:
85 is_guarded(rest, Nat.is_gt(Deep.binders(kids, 0n), 1n) && Bool.not(Deep.is_last(kids, at)))
86 case Con{a, rest} False{}:
87 is_guarded(rest, False{})