Permalink
Browse files

[enhance] libbase, traverse: added sub_option to traverse utils

  • Loading branch information...
1 parent 8821425 commit a689f5f5d6c0c3d4920b4456fa8b14358ebbc7ca @BourgerieQuentin BourgerieQuentin committed Jan 26, 2012
Showing with 8 additions and 0 deletions.
  1. +7 −0 libbase/traverse.ml
  2. +1 −0 libbase/traverse.mli
View
@@ -50,6 +50,13 @@ struct
let sub_current e = (function [e] -> e | _ -> assert false), [e]
let sub_ignore x = (function [] -> x | _ -> assert false), []
+ let sub_option sub_e opt =
+ match opt with
+ | None -> (fun x -> assert (List.is_empty x); None), []
+ | Some e ->
+ let usub, l = sub_e e in
+ (fun l -> Some (usub l)), l
+
let wrap cons (unsub,l) = (fun l -> cons (unsub l)), l
end
@@ -69,6 +69,7 @@ module Utils : sig
val sub_3 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a1 * 'a2 * 'a3, 'at, 'bt, 'b1 * 'b2 * 'b3) sub
val sub_4 : ('a1, 'at, 'bt, 'b1) sub -> ('a2, 'at, 'bt, 'b2) sub -> ('a3, 'at, 'bt, 'b3) sub -> ('a4, 'at, 'bt, 'b4) sub -> ('a1 * 'a2 * 'a3 * 'a4, 'at, 'bt, 'b1 * 'b2 * 'b3 * 'b4) sub
val sub_list : ('a, 'at, 'bt, 'b) sub -> ('a list, 'at, 'bt, 'b list) sub
+ val sub_option : ('a, 'at, 'bt, 'b) sub -> ('a option, 'at, 'bt, 'b option) sub
val sub_current : ('a, 'a, 'b, 'b) sub
val sub_ignore : ('a, _, _, 'a) sub

0 comments on commit a689f5f

Please sign in to comment.