def smaller

bend-kit-property@0.4.0.0 · property.bend:10

import bend-kit-property@0.4.0.0/property.bend as Property
import Base

10# Scan candidates in order; a predicate returns its input so affine values work.
11def smaller(~T: Type, ~test: T -> T & Bool, xs: List<&1, T>, tested: T & Bool) -> Maybe<&1, T>:
12  match xs:
13    case Nil{}:
14      (candidate, ok) = tested
15      match ok:
16        case False{}:
17          Some{candidate}
18        case True{}:
19          None{}
20    case Con{x, rest}:
21      (candidate, ok) = tested
22      match ok:
23        case False{}:
24          Some{candidate}
25        case True{}:
26          smaller(~T, ~test, rest, test(x))

Uses (5)

Used by (1)