CCList.(>|=) map operator

This commit is contained in:
Simon Cruanes 2014-11-08 01:00:05 +01:00
parent 81a640cf56
commit dc7b774120
2 changed files with 10 additions and 4 deletions

View file

@ -51,6 +51,8 @@ let map f l =
List.rev (List.rev_map f l) = map f l) List.rev (List.rev_map f l) = map f l)
*) *)
let (>|=) l f = map f l
let append l1 l2 = let append l1 l2 =
let rec direct i l1 l2 = match l1 with let rec direct i l1 l2 = match l1 with
| [] -> l2 | [] -> l2
@ -448,7 +450,7 @@ module Assoc = struct
let rec search eq acc l x y = match l with let rec search eq acc l x y = match l with
| [] -> (x,y)::acc | [] -> (x,y)::acc
| (x',y')::l' -> | (x',y')::l' ->
if eq x x' if eq x x'
then (x,y)::List.rev_append acc l' then (x,y)::List.rev_append acc l'
else search eq ((x',y')::acc) l' x y else search eq ((x',y')::acc) l' x y
in search eq [] l x y in search eq [] l x y
@ -497,7 +499,7 @@ module Zipper = struct
| l, x::r -> | l, x::r ->
begin match f (Some x) with begin match f (Some x) with
| None -> l,r | None -> l,r
| Some x' -> l, x::r | Some _ -> l, x::r
end end
let focused = function let focused = function
@ -661,7 +663,7 @@ let of_klist l =
let pp ?(start="[") ?(stop="]") ?(sep=", ") pp_item buf l = let pp ?(start="[") ?(stop="]") ?(sep=", ") pp_item buf l =
let rec print l = match l with let rec print l = match l with
| x::((y::xs) as l) -> | x::((_::_) as l) ->
pp_item buf x; pp_item buf x;
Buffer.add_string buf sep; Buffer.add_string buf sep;
print l 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 print ?(start="[") ?(stop="]") ?(sep=", ") pp_item fmt l =
let rec print fmt l = match l with let rec print fmt l = match l with
| x::((y::xs) as l) -> | x::((_::_) as l) ->
pp_item fmt x; pp_item fmt x;
Format.pp_print_string fmt sep; Format.pp_print_string fmt sep;
Format.pp_print_cut fmt (); Format.pp_print_cut fmt ();

View file

@ -33,6 +33,10 @@ val empty : 'a t
val map : ('a -> 'b) -> 'a t -> 'b t val map : ('a -> 'b) -> 'a t -> 'b t
(** Safe version of map *) (** 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 val append : 'a t -> 'a t -> 'a t
(** Safe version of append *) (** Safe version of append *)