Skip to content

+ Sequential for Choice with (v)options #629

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
16 changes: 15 additions & 1 deletion src/FSharpPlus/Extensions/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ module Extensions =
| ValueSome x -> Choice2Of2 x
#endif

/// Returns the Choice2Of2 if it contains an Choice2Of2 element, otherwise the option inside a Choice1Of2.
static member Sequential (t: option<Choice<'T, 'Choice2Of2>>) : Choice<'T option, 'Choice2Of2> =
match t with
| Some (Choice1Of2 x) -> Choice1Of2 (Some x)
| Some (Choice2Of2 x) -> Choice2Of2 x
| None -> Choice1Of2 None

/// Returns the Choice2Of2 if it contains an Choice2Of2 element, otherwise the option inside a Choice1Of2.
static member Sequential (t: voption<Choice<'T, 'Choice2Of2>>) : Choice<'T voption, 'Choice2Of2> =
match t with
| ValueSome (Choice1Of2 x) -> Choice1Of2 (ValueSome x)
| ValueSome (Choice2Of2 x) -> Choice2Of2 x
| ValueNone -> Choice1Of2 ValueNone


/// Returns all Choice2Of2's combined, otherwise a sequence of all Choice1Of2 elements.
static member Parallel (choice2Combiner, t: seq<Choice<'T1, 'T2>>) =
Expand Down Expand Up @@ -438,4 +452,4 @@ module Extensions =
match t with
| ValueSome (Ok x) -> Ok (ValueSome x)
| ValueNone -> Ok ValueNone
| ValueSome (Error x) -> Error x
| ValueSome (Error x) -> Error x
Loading