diff options
author | 2016-08-17 16:17:17 +0200 | |
---|---|---|
committer | 2016-08-17 16:17:17 +0200 | |
commit | 13fb26d615cdb03a4c4841c20b108deab2de60b3 (patch) | |
tree | 55f86d47695ee2071d1f886ce70ad7eec6a1e866 /lib | |
parent | 3fd0b8ad700bd77aabdd3f3f33b13ba5e93d8bc8 (diff) | |
parent | bc7ffd368789cb82bb8fc8b642b3de870b92c897 (diff) |
Merge branch 'v8.6'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cList.ml | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/cList.ml b/lib/cList.ml index 602bba6a5..c8283e3c7 100644 --- a/lib/cList.ml +++ b/lib/cList.ml @@ -601,19 +601,35 @@ let filter2 f l1 l2 = filter2_loop f c1 c2 l1 l2; (c1.tail, c2.tail) -let rec map_filter f = function - | [] -> [] - | x::l -> - let l' = map_filter f l in - match f x with None -> l' | Some y -> y::l' +let rec map_filter_loop f p = function + | [] -> () + | x :: l -> + match f x with + | None -> map_filter_loop f p l + | Some y -> + let c = { head = y; tail = [] } in + p.tail <- cast c; + map_filter_loop f c l + +let map_filter f l = + let c = { head = Obj.magic 0; tail = [] } in + map_filter_loop f c l; + c.tail -let map_filter_i f = - let rec aux i = function - | [] -> [] - | x::l -> - let l' = aux (succ i) l in - match f i x with None -> l' | Some y -> y::l' - in aux 0 +let rec map_filter_i_loop f i p = function + | [] -> () + | x :: l -> + match f i x with + | None -> map_filter_i_loop f (succ i) p l + | Some y -> + let c = { head = y; tail = [] } in + p.tail <- cast c; + map_filter_i_loop f (succ i) c l + +let map_filter_i f l = + let c = { head = Obj.magic 0; tail = [] } in + map_filter_i_loop f 0 c l; + c.tail let rec filter_with filter l = match filter, l with | [], [] -> [] |