Quantify List, Set, Dict or a single value according to a predicate
Quantifier type describes the result of the quantification.
list : (a -> Basics.Bool) -> List a -> Quantifier
Quantify a list according to a predicate.
isEven : Int -> Bool
isEven number =
modBy 2 number == 0
Quantify.list isEven [1,3,5,7]
--> None
Quantify.list isEven [0,1,2,3]
--> Some
Quantify.list isEven [0,2,4,6]
--> All
Quantify.list isEven []
--> None
set : (comparable -> Basics.Bool) -> Set comparable -> Quantifier
Quantify a set according to a predicate.
import Set
isEven : Int -> Bool
isEven number =
modBy 2 number == 0
Quantify.set isEven (Set.fromList [1,3,5,7])
--> None
Quantify.set isEven (Set.fromList [0,1,2,3])
--> Some
Quantify.set isEven (Set.fromList [0,2,4,6])
--> All
Quantify.set isEven Set.empty
--> None
dict : (comparable -> a -> Basics.Bool) -> Dict comparable a -> Quantifier
Quantify a dict according to a predicate. The predicate gets both the key and the value.
import Dict
isEven : Int -> Bool
isEven number =
modBy 2 number == 0
Quantify.dict (\key value -> isEven value) (Dict.fromList [(0,1),(1,3),(2,5),(3,7)])
--> None
Quantify.dict (\key value -> isEven value) (Dict.fromList [(0,0),(1,1),(2,2),(3,3)])
--> Some
Quantify.dict (\key value -> isEven value) (Dict.fromList [(0,0),(1,2),(2,4),(3,6)])
--> All
Quantify.dict (\key value -> isEven value) Dict.empty
--> None
single : (a -> Basics.Bool) -> a -> Quantifier
Quantify a single value according to a predicate.
isEven : Int -> Bool
isEven number =
modBy 2 number == 0
Quantify.single isEven 1
--> None
Quantify.single isEven 0
--> All
fromBool : Basics.Bool -> Quantifier
Quantify a Bool value according to a predicate.
Quantify.fromBool True
--> All
Quantify.fromBool False
--> None