From 73201a4e6714f1ebf55e79238f15abe667061379 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 6 Nov 2014 13:48:03 +0100 Subject: [PATCH 1/4] add some warnings (to be fixed) --- _tags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tags b/_tags index e89e7e22..5a3bb15a 100644 --- a/_tags +++ b/_tags @@ -160,4 +160,4 @@ : thread : thread : -traverse -<{string,core}/**/*.ml>: warn_K, warn_Y, warn_X +<{string,core}/**/*.ml>: warn_A, warn(-4) From ed3bf4ba267d9e7756faf93b886b7ba2ff549efc Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 6 Nov 2014 16:08:36 +0100 Subject: [PATCH 2/4] CCList.(>|=) infix map --- core/CCList.ml | 4 +++- core/CCList.mli | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/CCList.ml b/core/CCList.ml index cddb1911..03713d62 100644 --- a/core/CCList.ml +++ b/core/CCList.ml @@ -51,6 +51,8 @@ let map f l = List.rev (List.rev_map f l) = map f l) *) +let (>|=) l f = map f l + let append l1 l2 = let rec direct i l1 l2 = match l1 with | [] -> l2 @@ -550,7 +552,7 @@ module type MONAD = sig end module Traverse(M : MONAD) = struct - open M + open! M let map_m f l = let rec aux f acc l = match l with diff --git a/core/CCList.mli b/core/CCList.mli index 65356855..939888c4 100644 --- a/core/CCList.mli +++ b/core/CCList.mli @@ -33,6 +33,10 @@ val empty : 'a t val map : ('a -> 'b) -> 'a t -> 'b t (** Safe version of map *) +val (>|=) : 'a t -> ('a -> 'b) -> 'b t +(** Infix version of [map] with reversed arguments + @since NEXT_RELEASE *) + val append : 'a t -> 'a t -> 'a t (** Safe version of append *) From 443850588511186723298f316933a6780935138d Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 6 Nov 2014 16:30:08 +0100 Subject: [PATCH 3/4] disable warning 44 --- .merlin | 2 +- _tags | 2 +- core/CCList.ml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.merlin b/.merlin index 728816da..933075fd 100644 --- a/.merlin +++ b/.merlin @@ -15,4 +15,4 @@ PKG benchmark PKG threads PKG threads.posix PKG lwt -FLG -w +K,+Y,+X +FLG -w +a -w -4 -w -44 diff --git a/_tags b/_tags index 5a3bb15a..37a53b13 100644 --- a/_tags +++ b/_tags @@ -160,4 +160,4 @@ : thread : thread : -traverse -<{string,core}/**/*.ml>: warn_A, warn(-4) +<{string,core}/**/*.ml>: warn_A, warn(-4), warn(-44) diff --git a/core/CCList.ml b/core/CCList.ml index 03713d62..64cd4b9e 100644 --- a/core/CCList.ml +++ b/core/CCList.ml @@ -552,7 +552,7 @@ module type MONAD = sig end module Traverse(M : MONAD) = struct - open! M + open M let map_m f l = let rec aux f acc l = match l with From fcf950e9455b969092249eee99d9fe7e5c18083d Mon Sep 17 00:00:00 2001 From: Drup Date: Fri, 7 Nov 2014 08:48:19 +0100 Subject: [PATCH 4/4] Add CCOpt.filter. --- core/CCOpt.ml | 4 ++++ core/CCOpt.mli | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/core/CCOpt.ml b/core/CCOpt.ml index 40bd8e58..b99176de 100644 --- a/core/CCOpt.ml +++ b/core/CCOpt.ml @@ -84,6 +84,10 @@ let map2 f o1 o2 = match o1, o2 with | _, None -> None | Some x, Some y -> Some (f x y) +let filter p = function + | Some x as o when p x -> o + | o -> o + let iter f o = match o with | None -> () | Some x -> f x diff --git a/core/CCOpt.mli b/core/CCOpt.mli index 48b7ec4a..838f04e7 100644 --- a/core/CCOpt.mli +++ b/core/CCOpt.mli @@ -60,6 +60,11 @@ val iter : ('a -> unit) -> 'a t -> unit val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a (** Fold on 0 or 1 elements *) +val filter : ('a -> bool) -> 'a t -> 'a t +(** Filter on 0 or 1 elements + + @since NEXT_RELEASE *) + val get : 'a -> 'a t -> 'a (** [get default x] unwraps [x], but if [x = None] it returns [default] instead. @since NEXT_RELEASE *)