|
rpm-build |
0f2925 |
(*
|
|
rpm-build |
0f2925 |
* Options - functions for the option type
|
|
rpm-build |
0f2925 |
* Copyright (C) 2003 Nicolas Cannasse
|
|
rpm-build |
0f2925 |
*
|
|
rpm-build |
0f2925 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0f2925 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0f2925 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0f2925 |
* version 2.1 of the License, or (at your option) any later version,
|
|
rpm-build |
0f2925 |
* with the special exception on linking described in file LICENSE.
|
|
rpm-build |
0f2925 |
*
|
|
rpm-build |
0f2925 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0f2925 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0f2925 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0f2925 |
* Lesser General Public License for more details.
|
|
rpm-build |
0f2925 |
*
|
|
rpm-build |
0f2925 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0f2925 |
* License along with this library; if not, write to the Free Software
|
|
rpm-build |
0f2925 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
rpm-build |
0f2925 |
*)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
(** Functions for the option type.
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
Options are an Ocaml standard type that can be either [None] (undefined)
|
|
rpm-build |
0f2925 |
or [Some x] where x can be any value. Options are widely used in Ocaml
|
|
rpm-build |
0f2925 |
to represent undefined values (a little like NULL in C, but in a type
|
|
rpm-build |
0f2925 |
and memory safe way). This module adds some functions for working with
|
|
rpm-build |
0f2925 |
options.
|
|
rpm-build |
0f2925 |
*)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val may : ('a -> unit) -> 'a option -> unit
|
|
rpm-build |
0f2925 |
(** [may f (Some x)] calls [f x] and [may f None] does nothing. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val map : ('a -> 'b) -> 'a option -> 'b option
|
|
rpm-build |
0f2925 |
(** [map f (Some x)] returns [Some (f x)] and [map None] returns [None]. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val default : 'a -> 'a option -> 'a
|
|
rpm-build |
0f2925 |
(** [default x (Some v)] returns [v] and [default x None] returns [x]. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val map_default : ('a -> 'b) -> 'b -> 'a option -> 'b
|
|
rpm-build |
0f2925 |
(** [map_default f x (Some v)] returns [f v] and [map_default f x None]
|
|
rpm-build |
0f2925 |
returns [x]. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val is_none : 'a option -> bool
|
|
rpm-build |
0f2925 |
(** [is_none None] returns [true] otherwise it returns [false]. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val is_some : 'a option -> bool
|
|
rpm-build |
0f2925 |
(** [is_some (Some x)] returns [true] otherwise it returns [false]. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val get : 'a option -> 'a
|
|
rpm-build |
0f2925 |
(** [get (Some x)] returns [x] and [get None] raises [No_value]. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
exception No_value
|
|
rpm-build |
0f2925 |
(** Raised when calling [get None]. *)
|