Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/FSharpPlus/Extensions/Observable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System
open System.Threading
open System.Threading.Tasks
open System.Runtime.ExceptionServices
open FSharpPlus.Internals.Errors
open FSharpPlus.Data

/// Additional operations on Observable<'T>
Expand Down Expand Up @@ -33,6 +34,14 @@ module Observable =
member _.OnError e = observer.OnNext (Error (ExceptionDispatchInfo.Capture e)) }}


/// Ignores the values resulting from each OnNext call.
/// Only the side-effects of the observable are preserved.
/// <param name="source">The source observable.</param>
/// <returns>An observable that ignores the values of the source observable.</returns>
let ignore (source: IObservable<'T>) : IObservable<unit> =
let source = nullArgCheck (nameof source) source

Observable.map ignore source


let toAsyncSeq (source: System.IObservable<'T>) : SeqT<Async<bool>, 'T> = monad.plus {
Expand Down
8 changes: 8 additions & 0 deletions src/FSharpPlus/Extensions/Option.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ module Option =
match pair with
| (true, x) -> Some x
| (false, _) -> None

/// <summary>Ignores the value inside the option, if any.</summary>
/// <param name="source">The option value.</param>
/// <returns><c>Some ()</c> if the option is <c>Some</c>, <c>None</c> otherwise.</returns>
let ignore (source: option<'T>) =
match source with
| Some _ -> Some ()
| None -> None
8 changes: 8 additions & 0 deletions src/FSharpPlus/Extensions/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,11 @@ module Result =
| Error e, Ok _, Ok _ | Ok _, Error e, Ok _ | Ok _, Ok _, Error e -> Error e
| Ok _, Error e1, Error e2 | Error e1, Ok _, Error e2 | Error e1, Error e2, Ok _ -> Error (combiner e1 e2)
| Error e1, Error e2, Error e3 -> Error (combiner (combiner e1 e2) e3)

/// <summary>Ignores the value inside the result, if any.</summary>
/// <param name="source">The result value.</param>
/// <returns><c>Ok ()</c> if the result is <c>Ok</c>, <c>Error e</c> otherwise.</returns>
let ignore (source: Result<'T, 'Error>) =
match source with
| Ok _ -> Ok ()
| Error e -> Error e
9 changes: 9 additions & 0 deletions src/FSharpPlus/Extensions/Seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,12 @@ module Seq =
|> nullArgCheck (nameof source)
|> Seq.indexed
|> Seq.choose (fun (a, b) -> mapping a b)

/// <summary>Ignores the values resulting from each iteration inside the sequence.</summary>
/// <param name="source">The sequence value.</param>
/// <returns> A sequence of unit values.</returns>
/// <remarks>It can be used to convert a non-generic IEnumerable to a unit seq.</remarks>
let ignore (source: Collections.IEnumerable) =
let source = nullArgCheck (nameof source) source

seq { for _ in source do yield () }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I've not needed this.

8 changes: 8 additions & 0 deletions src/FSharpPlus/Extensions/ValueOption.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ module ValueOption =
match source with
| Some x -> ValueSome x
| None -> ValueNone

/// <summary>Ignores the value inside the option, if any.</summary>
/// <param name="source">The option value.</param>
/// <returns><c>ValueSome ()</c> if the option is <c>ValueSome</c>, <c>ValueNone</c> otherwise.</returns>
let ignore (source: ValueOption<'T>) =
match source with
| ValueSome _ -> ValueSome ()
| ValueNone -> ValueNone
Loading