From eb9263c83a812a5872e4305bdd87f8a2ffe2dfc3 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Thu, 20 Sep 2018 16:35:00 -0400 Subject: [PATCH] Add option iter --- compiler/src/lib/tiger/tiger_opt.ml | 3 +++ compiler/src/lib/tiger/tiger_opt.mli | 2 ++ 2 files changed, 5 insertions(+) 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 -- 2.20.1