Noogλe
search input
Function of the day
Split type into two subtypes by predicate
p
, take all elements of the first subtype to be less than all the elements of the second subtype, compare elements of a single subtype withyes
andno
respectively.Inputs
p
-
Predicate
yes
-
Comparison function if predicate holds for both values
no
-
Comparison function if predicate holds for neither value
a
-
First value to compare
b
-
Second value to compare
Type
(a -> bool) -> (a -> a -> int) -> (a -> a -> int) -> (a -> a -> int)
Examples
lib.trivial.splitByAndCompare
usage examplelet cmp = splitByAndCompare (hasPrefix "foo") compare compare; in cmp "a" "z" => -1 cmp "fooa" "fooz" => -1 cmp "f" "a" => 1 cmp "fooa" "a" => -1 # while compare "fooa" "a" => 1