Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/FSharpPlus/Control/Functor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type Unzip =
#endif

static member Unzip ((source: Async<'T * 'U> , _output: Async<'T> * Async<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Result<'T * 'U, 'E> , _output: Result<'T,'E> * Result<'U,'E> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Result<'T * 'U, 'E> , _output: Result<'T,'E> * Result<'U,'E> ) , _mthd: Unzip ) = Result.unzip source
static member Unzip ((source: Choice<'T * 'U, 'E> , _output: Choice<'T,'E> * Choice<'U,'E> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: KeyValuePair<'Key, 'T * 'U> , _output: KeyValuePair<_, 'T> * KeyValuePair<_, 'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Map<'Key, 'T * 'U> , _output: Map<_, 'T> * Map<_, 'U> ) , _mthd: Unzip ) = Map.unzip source
Expand Down Expand Up @@ -203,6 +203,7 @@ type Zip =
static member Zip ((x: 'T [] , y: 'U [] , _output: ('T*'U) [] ), _mthd: Zip) = Array.zipShortest x y
static member Zip ((x: ResizeArray<'T> , y: ResizeArray<'U> , _output: ResizeArray<'T*'U> ), _mthd: Zip) = ResizeArray.zipShortest x y
static member Zip ((x: option<'T> , y: option<'U> , _output: option<'T*'U> ), _mthd: Zip) = Option.zip x y
static member Zip ((x: Result<'T, 'Error> , y: Result<'U, 'Error> , _output: Result<'T * 'U, 'Error> ), _mthd: Zip) = Result.zip x y
static member Zip ((x: Async<'T> , y: Async<'U> , _output: Async<'T*'U> ), _mthd: Zip) = Async.zip x y
#if !FABLE_COMPILER
static member Zip ((x: Task<'T> , y: Task<'U> , _output: Task<'T*'U> ), _mthd: Zip) = Task.zip x y
Expand Down
10 changes: 10 additions & 0 deletions src/FSharpPlus/Extensions/Option.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ module Option =
| Some x, Some y -> Some (x, y)
| _ -> None

/// <summary>If all 3 value are Some, returns them tupled. Otherwise it returns None.</summary>
/// <param name="x">The first value.</param>
/// <param name="y">The second value.</param>
/// <param name="z">The third value.</param>
/// <returns>The resulting option.</returns>
let zip3 x y z : option<'T * 'U * 'V> =
match x, y, z with
| Some x, Some y, Some z -> Some (x, y, z)
| _ -> None

/// <summary>Converts an option to a Result.</summary>
/// <param name="source">The option value.</param>
/// <returns>The resulting Result value.</returns>
Expand Down
19 changes: 19 additions & 0 deletions src/FSharpPlus/Extensions/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,26 @@ module Result =
/// <returns>An Ok of the function applied to the value, or the first <c>Error</c> if either the function or the value is <c>Error</c>.</returns>
let apply f (x: Result<'T,'Error>) : Result<'U,'Error> = match f, x with Ok a, Ok b -> Ok (a b) | Error e, _ | _, Error e -> Error e

/// <summary>If value is Ok, returns both of them tupled. Otherwise it returns the Error value twice in a tuple.</summary>
/// <param name="v">The value.</param>
/// <returns>The resulting tuple.</returns>
let unzip (source: Result<'T * 'U, 'Error>) : Result<'T, 'Error> * Result<'U, 'Error> = match source with Ok (x, y) -> Ok x, Ok y | Error e -> Error e, Error e

/// <summary>Creates a Result value from a pair of Result values.</summary>
/// <param name="x">The first Result value.</param>
/// <param name="y">The second Result value.</param>
///
/// <returns>The tupled value, or the first Error.</returns>
let zip (x: Result<'T, 'Error>) (y: Result<'U, 'Error>) : Result<'T * 'U, 'Error> = match x, y with Ok a, Ok b -> Ok (a, b) | Error e, _ | _, Error e -> Error e

/// <summary>Creates a Result value from a three Result values.</summary>
/// <param name="x">The first Result value.</param>
/// <param name="y">The second Result value.</param>
/// <param name="z">The third Result value.</param>
///
/// <returns>The tupled value, or the first Error.</returns>
let zip3 (x: Result<'T, 'Error>) (y: Result<'U, 'Error>) (z: Result<'V, 'Error>) : Result<'T * 'U * 'V, 'Error> = match x, y, z with Ok a, Ok b, Ok c -> Ok (a, b, c) | Error e, _, _ | _, Error e, _ | _, _, Error e -> Error e

/// <summary>Creates a Result value from a pair of Result values, using a function to combine them.</summary>
/// <param name="f">The mapping function.</param>
/// <param name="x">The first Result value.</param>
Expand Down