def eager

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

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

35# Functions
36# =========
37# What an application with the nodes `kids` computes whether needed or not, as its node at `at` is one of its
38# arguments: "pick" for a value of Bool.pick, "&&" or "||" for their right side, "" for none.
39def eager(kids: List<&2, Lint.Node>, +at: U32) -> String:
40  match kids:
41    case Con{Lint.Node{Lint.Reference{t}, n, s, k, f}, Con{ty, Con{c, Con{x, Con{y, rest}}}}}:
42      Bool.pick(
43        String,
44        String.eq(t, "Bool.pick") && (U32.is_eq(at, 3) || U32.is_eq(at, 4)),
45        "pick",
46        ""
47      )
48    case Con{Lint.Node{Lint.Reference{+t}, n, s, k, f}, Con{left, Con{right, Nil{}}}}:
49      Bool.pick(
50        String,
51        U32.is_eq(at, 2),
52        Bool.pick(
53          String,
54          String.eq(t, "Bool.and"),
55          "&&",
56          Bool.pick(String, String.eq(t, "Bool.or"), "||", "")
57        ),
58        ""
59      )
60    case _:
61      ""

Uses (10)

Used by (1)