diff --git a/src/FSharpPlus/Extensions/Observable.fs b/src/FSharpPlus/Extensions/Observable.fs
index 3588b49a2..f77109d8b 100644
--- a/src/FSharpPlus/Extensions/Observable.fs
+++ b/src/FSharpPlus/Extensions/Observable.fs
@@ -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>
@@ -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.
+ /// The source observable.
+ /// An observable that ignores the values of the source observable.
+ let ignore (source: IObservable<'T>) : IObservable =
+ let source = nullArgCheck (nameof source) source
+
+ Observable.map ignore source
let toAsyncSeq (source: System.IObservable<'T>) : SeqT, 'T> = monad.plus {
diff --git a/src/FSharpPlus/Extensions/Option.fs b/src/FSharpPlus/Extensions/Option.fs
index 191f634ad..d62c7086a 100644
--- a/src/FSharpPlus/Extensions/Option.fs
+++ b/src/FSharpPlus/Extensions/Option.fs
@@ -71,6 +71,14 @@ module Option =
| (true, x) -> Some x
| (false, _) -> None
+ /// Ignores the value inside the option, if any.
+ /// The option value.
+ /// Some () if the option is Some, None otherwise.
+ let ignore (source: option<'T>) =
+ match source with
+ | Some _ -> Some ()
+ | None -> None
+
///
/// Extracts a value from either side of an Option.
///
diff --git a/src/FSharpPlus/Extensions/Result.fs b/src/FSharpPlus/Extensions/Result.fs
index c30c618cf..a243a2a33 100644
--- a/src/FSharpPlus/Extensions/Result.fs
+++ b/src/FSharpPlus/Extensions/Result.fs
@@ -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)
+
+ /// Ignores the value inside the result, if any.
+ /// The result value.
+ /// Ok () if the result is Ok, Error e otherwise.
+ let ignore (source: Result<'T, 'Error>) =
+ match source with
+ | Ok _ -> Ok ()
+ | Error e -> Error e
diff --git a/src/FSharpPlus/Extensions/Seq.fs b/src/FSharpPlus/Extensions/Seq.fs
index c7d841f05..6108fc365 100644
--- a/src/FSharpPlus/Extensions/Seq.fs
+++ b/src/FSharpPlus/Extensions/Seq.fs
@@ -361,3 +361,12 @@ module Seq =
|> nullArgCheck (nameof source)
|> Seq.indexed
|> Seq.choose (fun (a, b) -> mapping a b)
+
+ /// Ignores the values resulting from each iteration inside the sequence.
+ /// The sequence value.
+ /// A sequence of unit values.
+ /// It can be used to convert a non-generic IEnumerable to a unit seq.
+ let ignore (source: Collections.IEnumerable) =
+ let source = nullArgCheck (nameof source) source
+
+ seq { for _ in source do yield () }
diff --git a/src/FSharpPlus/Extensions/ValueOption.fs b/src/FSharpPlus/Extensions/ValueOption.fs
index 3ff9bd41a..67bbb4289 100644
--- a/src/FSharpPlus/Extensions/ValueOption.fs
+++ b/src/FSharpPlus/Extensions/ValueOption.fs
@@ -81,7 +81,15 @@ module ValueOption =
let ofOption (source: option<'T>) =
match source with
| Some x -> ValueSome x
- | None -> ValueNone
+ | None -> ValueNone
+
+ /// Ignores the value inside the option, if any.
+ /// The option value.
+ /// ValueSome () if the option is ValueSome, ValueNone otherwise.
+ let ignore (source: ValueOption<'T>) =
+ match source with
+ | ValueSome _ -> ValueSome ()
+ | ValueNone -> ValueNone
///
/// Extracts a value from either side of a ValueOption.
@@ -90,4 +98,6 @@ module ValueOption =
/// The function to apply if the option is ValueNone.
/// The option to extract the value from.
let inline either ([]fSome: 'T -> 'U) ([]fNone: unit -> 'U) (source: ValueOption<'T>) : 'U =
- match source with ValueSome v -> fSome v | ValueNone -> fNone ()
+ match source with
+ | ValueSome v -> fSome v
+ | ValueNone -> fNone ()