From: Siraaj Khandkar Date: Thu, 20 Sep 2018 20:35:00 +0000 (-0400) Subject: Add option iter X-Git-Url: https://git.xandkar.net/?p=tiger.ml.git;a=commitdiff_plain;h=eb9263c83a812a5872e4305bdd87f8a2ffe2dfc3 Add option iter --- diff --git a/compiler/src/lib/tiger/tiger_opt.ml b/compiler/src/lib/tiger/tiger_opt.ml index cdacd0e..8eee986 100644 --- a/compiler/src/lib/tiger/tiger_opt.ml +++ b/compiler/src/lib/tiger/tiger_opt.ml @@ -5,6 +5,9 @@ let map t f = | None -> None | Some x -> Some (f x) +let iter t ~f = + ignore (map t f) + let get t ~default = match t with | None -> default diff --git a/compiler/src/lib/tiger/tiger_opt.mli b/compiler/src/lib/tiger/tiger_opt.mli index 719e854..662ca4a 100644 --- a/compiler/src/lib/tiger/tiger_opt.mli +++ b/compiler/src/lib/tiger/tiger_opt.mli @@ -2,4 +2,6 @@ type 'a t = 'a option val map : 'a t -> ('a -> 'b) -> 'b t +val iter : 'a t -> f:('a -> unit) -> unit + val get : 'a t -> default:'a -> 'a