From dc7b774120beeaa906d9f1c3ed62c477f8130ede Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 8 Nov 2014 01:00:05 +0100 Subject: [PATCH] CCList.(>|=) map operator --- core/CCList.ml | 10 ++++++---- core/CCList.mli | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/CCList.ml b/core/CCList.ml index cddb1911..961d1fd8 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 @@ -448,7 +450,7 @@ module Assoc = struct let rec search eq acc l x y = match l with | [] -> (x,y)::acc | (x',y')::l' -> - if eq x x' + if eq x x' then (x,y)::List.rev_append acc l' else search eq ((x',y')::acc) l' x y in search eq [] l x y @@ -497,7 +499,7 @@ module Zipper = struct | l, x::r -> begin match f (Some x) with | None -> l,r - | Some x' -> l, x::r + | Some _ -> l, x::r end let focused = function @@ -661,7 +663,7 @@ let of_klist l = let pp ?(start="[") ?(stop="]") ?(sep=", ") pp_item buf l = let rec print l = match l with - | x::((y::xs) as l) -> + | x::((_::_) as l) -> pp_item buf x; Buffer.add_string buf sep; print l @@ -675,7 +677,7 @@ let pp ?(start="[") ?(stop="]") ?(sep=", ") pp_item buf l = let print ?(start="[") ?(stop="]") ?(sep=", ") pp_item fmt l = let rec print fmt l = match l with - | x::((y::xs) as l) -> + | x::((_::_) as l) -> pp_item fmt x; Format.pp_print_string fmt sep; Format.pp_print_cut fmt (); 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 *)