You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/FSharpPlus/Data/Seq.fs
+55Lines changed: 55 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -797,6 +797,61 @@ module SeqT_V2 =
797
797
let inlineiteri<'T,..>(f:int ->'T ->unit)(source:SeqT<'``Monad<bool>``,'T>):'``Monad<unit>`` = iteriM (fun i x -> result (f i x)) source
798
798
let inlineiter<'T,..>f (source:SeqT<'``Monad<bool>``,'T>):'``Monad<unit>`` = iterM (f >> result) source
799
799
800
+
let inlineinternaltryPickMAndMap<'T,'U,..>(f:'T ->'``Monad<'Uoption>``)(source:SeqT<'``Monad<bool>``,'T>)(postMap:'U option ->'V):'``Monad<'V>`` = innerMonad2<_, '``Monad<unit>``>(){
801
+
use ie =(source :> IEnumerableM<'``Monad<bool>``, 'T>).GetEnumerator ()
802
+
let!(move:bool)= ie.MoveNext ()
803
+
let mutableb= move
804
+
let mutableres= None
805
+
while b && res.IsNone do
806
+
let!(fv:'U option)= f ie.Current
807
+
match fv with
808
+
| Some _as r -> res <- r
809
+
| None ->
810
+
let!moven= ie.MoveNext ()
811
+
b <- moven
812
+
return postMap res }
813
+
814
+
let inlineinternaltryPickAndMap<'T,'U,..>(f:'T ->'U option)(source:SeqT<'``Monad<bool>``,'T>)(postMap:'U option ->'V):'``Monad<'V>`` = innerMonad2<_, '``Monad<unit>``>(){
815
+
use ie =(source :> IEnumerableM<'``Monad<bool>``, 'T>).GetEnumerator ()
816
+
let!(move:bool)= ie.MoveNext ()
817
+
let mutableb= move
818
+
let mutableres= None
819
+
while b && res.IsNone do
820
+
let(fv:'U option)= f ie.Current
821
+
match fv with
822
+
| Some _as r -> res <- r
823
+
| None ->
824
+
let!moven= ie.MoveNext ()
825
+
b <- moven
826
+
return postMap res }
827
+
828
+
let inlinetryPickM<'T,'U,..>(f:'T ->'``Monad<'Uoption>``)(source:SeqT<'``Monad<bool>``,'T>):'``Monad<'Uoption>`` =
829
+
tryPickMAndMap<_, 'U,_, '``Monad<unit>``,_,_,_> f source id
830
+
831
+
let inlinepickM<'T,'U,..>(f:'T ->'``Monad<'Uoption>``)(source:SeqT<'``Monad<bool>``,'T>):'``Monad<'U>`` =
832
+
tryPickMAndMap<_, 'U, '``Monad<'U option>``, '``Monad<unit>``,_,_,_> f source (function Some v ->(v: 'U)|_-> raise (KeyNotFoundException ()))
833
+
834
+
let inlinetryPick<'T,'U,..>(f:'T ->'U option)(source:SeqT<'``Monad<bool>``,'T>):'``Monad<'Uoption>`` =
835
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_> f source id
836
+
837
+
let inlinepick(f:'T ->'U option)(source:SeqT<'``Monad<bool>``,'T>):'``Monad<'U>`` =
838
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_> f source (function Some v ->(v: 'U)|_-> raise (KeyNotFoundException ()))
839
+
840
+
let inlinecontains value (source:SeqT<'``Monad<bool>``,'T>):'``Monad<bool>`` =
841
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_>(fun v ->if v = value then Some ()else None) source Option.isSome
842
+
843
+
let inlinetryFind<'T,..>f (source:SeqT<'``Monad<bool>``,'T>):'``Monad<'Toption>`` =
844
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_>(fun v ->if f v then Some v else None) source id
845
+
846
+
let inlinefind f (source:SeqT<'``Monad<bool>``,'T>):'``Monad<'T>`` =
847
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_>(fun v ->if f v then Some v else None) source (function Some v ->(v: 'T)|_-> raise (KeyNotFoundException ()))
848
+
849
+
let inlineexists f (source:SeqT<'``Monad<bool>``,'T>):'``Monad<bool>`` =
850
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_>(fun v ->if f v then Some v else None) source Option.isSome
851
+
852
+
let inlineforall f (source:SeqT<'``Monad<bool>``,'T>):'``Monad<bool>`` =
853
+
tryPickAndMap<_,_,_,_, '``Monad<unit>``,_>(fun v ->if f v then None else Some v) source Option.isNone
0 commit comments