add some functions using result

This commit is contained in:
Simon Cruanes 2018-01-14 16:27:37 -06:00
parent 6b5f4cf40e
commit d860c832e0
6 changed files with 48 additions and 5 deletions

View file

@ -4,7 +4,5 @@ S tests/
B _build/src
B _build/tests/
B _build/bench/
PKG oUnit qcheck
PKG benchmark
FLG -safe-string
FLG -w+a-4-44-48-60@8
PKG oUnit qcheck result benchmark
FLG -safe-string -w+a-4-44-48-60@8

2
_oasis
View file

@ -30,7 +30,7 @@ Flag bigarray
Library "sequence"
Path: src/
Modules: Sequence, SequenceLabels
BuildDepends: bytes
BuildDepends: bytes, result
Library "invert"
Path: src/invert

1
opam
View file

@ -27,6 +27,7 @@ remove: [
depends: [
"ocamlfind"
"base-bytes"
"result"
"ocamlbuild" {build}
"qcheck" {test}
"qtest" {test}

View file

@ -230,6 +230,24 @@ let intersperse elem seq k =
|> OUnit.assert_equal [1;0;2;0;3;0;4;0;5;0]
*)
let keep_some seq k =
seq
(function
| Some x -> k x
| None -> ())
let keep_ok seq k =
seq
(function
| Result.Ok x -> k x
| Result.Error _ -> ())
let keep_error seq k =
seq
(function
| Result.Error x -> k x
| Result.Ok _ -> ())
(** Mutable unrolled list to serve as intermediate storage *)
module MList = struct
type 'a node =

View file

@ -231,6 +231,19 @@ val filter_count : ('a -> bool) -> 'a t -> int
val intersperse : 'a -> 'a t -> 'a t
(** Insert the single element between every element of the sequence *)
val keep_some : 'a option t -> 'a t
(** [filter_some l] retains only elements of the form [Some x].
Same as [filter_map (fun x->x)]
@since NEXT_RELEASE *)
val keep_ok : ('a, _) Result.result t -> 'a t
(** [keep_ok l] retains only elements of the form [Ok x].
@since NEXT_RELEASE *)
val keep_error : (_, 'e) Result.result t -> 'e t
(** [keep_error l] retains only elements of the form [Error x].
@since NEXT_RELEASE *)
(** {2 Caching} *)
val persistent : 'a t -> 'a t

View file

@ -204,6 +204,19 @@ val filter_count : f:('a -> bool) -> 'a t -> int
val intersperse : x:'a -> 'a t -> 'a t
(** Insert the single element between every element of the sequence *)
val keep_some : 'a option t -> 'a t
(** [filter_some l] retains only elements of the form [Some x].
Same as [filter_map (fun x->x)]
@since NEXT_RELEASE *)
val keep_ok : ('a, _) Result.result t -> 'a t
(** [keep_ok l] retains only elements of the form [Ok x].
@since NEXT_RELEASE *)
val keep_error : (_, 'e) Result.result t -> 'e t
(** [keep_error l] retains only elements of the form [Error x].
@since NEXT_RELEASE *)
(** {2 Caching} *)
val persistent : 'a t -> 'a t