(.module: [lux #* [control ["." function]]] [// [monoid (#+ Monoid)] [functor ["." contravariant]]]) (type: #export (Predicate a) (-> a Bit)) (template [ ] [(def: #export Predicate (function.constant )) (def: #export ( left right) (All [a] (-> (Predicate a) (Predicate a) (Predicate a))) (function (_ value) ( (left value) (right value))))] [none #0 unite or] [all #1 intersect and] ) (template [ ] [(implementation: #export (All [a] (Monoid (Predicate a))) (def: identity ) (def: compose ))] [union ..none ..unite] [intersection ..all ..intersect] ) (def: #export (complement predicate) (All [a] (-> (Predicate a) (Predicate a))) (|>> predicate not)) (def: #export (difference sub base) (All [a] (-> (Predicate a) (Predicate a) (Predicate a))) (function (_ value) (and (base value) (not (sub value))))) (def: #export (rec predicate) (All [a] (-> (-> (Predicate a) (Predicate a)) (Predicate a))) (function (recur input) (predicate recur input))) (implementation: #export functor (contravariant.Functor Predicate) (def: (map f fb) (|>> f fb)))