From e703a3f65530070c02e657b5ae313e6be5ff929a Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 7 Aug 2014 13:14:23 +0200 Subject: [PATCH] CCOrd.map --- core/CCOrd.ml | 2 ++ core/CCOrd.mli | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/core/CCOrd.ml b/core/CCOrd.ml index 8474e12e..7e05bf3f 100644 --- a/core/CCOrd.ml +++ b/core/CCOrd.ml @@ -89,3 +89,5 @@ let array_ ord a1 a2 = then aux (i+1) else c in aux 0 + +let map f ord a b = ord (f a) (f b) diff --git a/core/CCOrd.mli b/core/CCOrd.mli index 90e929d8..45d24259 100644 --- a/core/CCOrd.mli +++ b/core/CCOrd.mli @@ -64,3 +64,11 @@ val list_ : 'a t -> 'a list t (** Lexicographic combination on lists *) val array_ : 'a t -> 'a array t + +val map : ('a -> 'b) -> 'b t -> 'a t +(** [map f ord] is the comparison function that, given objects [x] and [y], + projects [x] and [y] using [f] (e.g. using a record field) and then + compares those projections with [ord]. + Example: + [map fst CCInt.compare] compares values of type [(int * 'a)] by their + first component. *)