(.require [library [lux (.except all or and not) [abstract [monoid (.only Monoid)] [functor ["[0]" contravariant]]]]] ["[0]" //]) (type .public (Predicate a) (-> a Bit)) (with_template [ ] [(def .public Predicate (//.constant )) (def .public ( left right) (All (_ a) (-> (Predicate a) (Predicate a) (Predicate a))) (function (_ value) ( (left value) (right value))))] [none #0 or .or] [all #1 and .and] ) (with_template [ ] [(def .public (All (_ a) (Monoid (Predicate a))) (implementation (def identity ) (def composite )))] [union ..none ..or] [intersection ..all ..and] ) (def .public (complement predicate) (All (_ a) (-> (Predicate a) (Predicate a))) (|>> predicate .not)) (def .public not (All (_ a) (-> (Predicate a) (Predicate a))) ..complement) (def .public (difference sub base) (All (_ a) (-> (Predicate a) (Predicate a) (Predicate a))) (function (_ value) (.and (base value) (.not (sub value))))) (def .public (rec predicate) (All (_ a) (-> (-> (Predicate a) (Predicate a)) (Predicate a))) (function (again input) (predicate again input))) (def .public functor (contravariant.Functor Predicate) (implementation (def (each f fb) (|>> f fb))))