splitByAndCompare
lib.splitByAndCompare
Docs pulled from | This Revision | about 1 hour ago
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 with yes
and no
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 example
let 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
Noogle detected
Implementation
The following is the current implementation of this function.
splitByAndCompare =
p: yes: no: a: b:
if p a
then if p b then yes a b else -1
else if p b then 1 else no a b;