From 7d1862a501572bf95ef1e20c356cc19da3d3af02 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 20 Nov 2019 17:50:40 -0600 Subject: [PATCH] wip: add `to_std_seq` see #254 --- containers.opam | 1 + src/core/CCOpt.ml | 5 ++- src/core/CCOpt.mli | 5 ++- src/core/dune | 76 ++++++++++++++++++++++++++++------------------ 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/containers.opam b/containers.opam index 855aa323..ea3244b5 100644 --- a/containers.opam +++ b/containers.opam @@ -13,6 +13,7 @@ depends: [ "dune" "result" "uchar" + "seq" "qtest" { with-test } "qcheck" { with-test } "ounit" { with-test } diff --git a/src/core/CCOpt.ml b/src/core/CCOpt.ml index d28ff739..45bba9b9 100644 --- a/src/core/CCOpt.ml +++ b/src/core/CCOpt.ml @@ -1,4 +1,3 @@ - (* This file is free software, part of containers. See file "license" for more details. *) (** {1 Options} *) @@ -210,6 +209,10 @@ let to_iter o k = match o with let to_seq = to_iter +let to_std_seq o () = match o with + | None -> Seq.Nil + | Some x -> Seq.Cons (x, Seq.empty) + let pp ppx out = function | None -> Format.pp_print_string out "None" | Some x -> Format.fprintf out "@[Some %a@]" ppx x diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index 6d400b23..5c8bb367 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -1,4 +1,3 @@ - (* This file is free software, part of containers. See file "license" for more details. *) (** {1 Options} *) @@ -187,6 +186,10 @@ val choice_seq : 'a t sequence -> 'a t val to_gen : 'a t -> 'a gen +val to_std_seq : 'a t -> 'a Seq.t +(** Same as {!Stdlib.Option.to_seq} + @since NEXT_RELEASE *) + val to_iter : 'a t -> 'a sequence (** Returns an internal iterator, like in the library [Iter]. @since NEXT_RELEASE *) diff --git a/src/core/dune b/src/core/dune index 08d84df2..e3a8d8ec 100644 --- a/src/core/dune +++ b/src/core/dune @@ -1,44 +1,62 @@ (alias - (name unlabel) - (deps (:mli CCArrayLabels.mli) ../unlabel.exe) - (action (run ../unlabel.exe %{mli} CCArray.mli))) + (name unlabel) + (deps + (:mli CCArrayLabels.mli) + ../unlabel.exe) + (action + (run ../unlabel.exe %{mli} CCArray.mli))) (alias - (name unlabel) - (deps (:mli CCArray_sliceLabels.mli) ../unlabel.exe) - (action (run ../unlabel.exe %{mli} CCArray_slice.mli))) + (name unlabel) + (deps + (:mli CCArray_sliceLabels.mli) + ../unlabel.exe) + (action + (run ../unlabel.exe %{mli} CCArray_slice.mli))) (alias - (name unlabel) - (deps (:mli CCEqualLabels.mli) ../unlabel.exe) - (action (run ../unlabel.exe %{mli} CCEqual.mli))) + (name unlabel) + (deps + (:mli CCEqualLabels.mli) + ../unlabel.exe) + (action + (run ../unlabel.exe %{mli} CCEqual.mli))) (alias - (name unlabel) - (deps (:mli CCListLabels.mli) ../unlabel.exe) - (action (run ../unlabel.exe %{mli} CCList.mli))) + (name unlabel) + (deps + (:mli CCListLabels.mli) + ../unlabel.exe) + (action + (run ../unlabel.exe %{mli} CCList.mli))) (alias - (name unlabel) - (deps (:mli CCStringLabels.mli) ../unlabel.exe) - (action (run ../unlabel.exe %{mli} CCString.mli))) - + (name unlabel) + (deps + (:mli CCStringLabels.mli) + ../unlabel.exe) + (action + (run ../unlabel.exe %{mli} CCString.mli))) (executable - (name mkshims) - (modules mkshims) - (libraries dune.configurator)) + (name mkshims) + (modules mkshims) + (libraries dune.configurator)) (rule - (targets CCShims_.ml CCShimsList_.ml CCShimsFun_.ml CCShimsFun_.mli CCShimsArray_.ml CCShimsFormat_.ml) - (deps ./mkshims.exe) - (action (run ./mkshims.exe))) + (targets CCShims_.ml CCShimsList_.ml CCShimsFun_.ml CCShimsFun_.mli + CCShimsArray_.ml CCShimsFormat_.ml) + (deps ./mkshims.exe) + (action + (run ./mkshims.exe))) (library - (name containers) - (public_name containers) - (wrapped false) - (modules :standard \ mkshims) - (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels -open CCMonomorphic) - (ocamlopt_flags (:include ../flambda.flags)) - (libraries result uchar containers.monomorphic)) + (name containers) + (public_name containers) + (wrapped false) + (modules :standard \ mkshims) + (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels -open + CCMonomorphic) + (ocamlopt_flags + (:include ../flambda.flags)) + (libraries result uchar seq containers.monomorphic))