Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ Result.Sequence #562

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/FSharpPlus/Extensions/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module Extensions =
| Some v -> yield v
| None -> ok <- false })
if ok then Some (Array.toSeq res) else None

type ValueOption<'t> with

/// Returns None if it contains a None element, otherwise a list of all elements
Expand All @@ -146,4 +147,19 @@ module Extensions =
match e.Current with
| ValueSome v -> yield v
| ValueNone -> ok <- false })
if ok then ValueSome (Array.toSeq res) else ValueNone
if ok then ValueSome (Array.toSeq res) else ValueNone

type Result<'t, 'error> with

/// Returns the first Error if it contains an Error element, otherwise a list of all elements
static member Sequence (t: seq<Result<'T, ' Error>>) =
let mutable bad = None
let res = Seq.toArray (seq {
use e = t.GetEnumerator ()
while e.MoveNext () && bad.IsNone do
match e.Current with
| Ok v -> yield v
| Error x -> bad <- Some x })
match bad with
| None-> Ok (Array.toSeq res)
| Some x -> Error x
Loading