Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / basis-library / general / option.sml
CommitLineData
7f918cf1
CE
1(* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
4 *
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
7 *)
8
9structure Option: OPTION =
10struct
11
12datatype option = datatype option
13
14exception Option
15
16fun map f =
17 fn NONE => NONE
18 | SOME a => SOME (f a)
19
20fun app f z = (ignore (map f z); ())
21
22fun compose (f, g) c = map f (g c)
23
24val join =
25 fn NONE => NONE
26 | SOME v => v
27
28fun mapPartial f = join o (map f)
29
30fun composePartial (f, g) = (mapPartial f) o g
31
32fun filter f a = if f a then SOME a else NONE
33
34fun getOpt (z, a) =
35 case z of
36 NONE => a
37 | SOME v => v
38
39val isSome =
40 fn NONE => false
41 | SOME _ => true
42
43val valOf =
44 fn NONE => raise Option
45 | SOME v => v
46
47end
48
49structure OptionGlobal: OPTION_GLOBAL = Option
50open OptionGlobal