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
34 changes: 31 additions & 3 deletions src/FSharpPlus/Operators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ open FSharpPlus.Control
[<AutoOpenAttribute>]
module Operators =

open FSharpPlus.Internals.Errors

// Common combinators

/// <summary>Creates a new function with first two arguments flipped.</summary>
Expand Down Expand Up @@ -1657,8 +1659,34 @@ module Operators =
/// <category index="23">Additional Functions</category>
let inline (|Parsed|_|) str : 'T option = tryParse str

#endif
#endif

/// <summary>
/// An active pattern to match strings in a case-insensitive way.
/// </summary>
/// <category index="23">Additional Functions</category>
let (|CiString|_|) (ciString: string) (source: string) : unit option =
let ciString = nullArgCheck (nameof ciString) ciString
let source = nullArgCheck (nameof source) source

match source with
| s when s.Equals(ciString, StringComparison.OrdinalIgnoreCase) -> Some ()
| _ -> None

#if !FABLE_COMPILER

/// <summary>
/// An active pattern to match AggregateException and extract its inner exceptions as a list.
/// </summary>
/// <category index="23">Additional Functions</category>
let (|AggregateException|_|) (exn: exn) : exn list option =
let exn = nullArgCheck (nameof exn) exn

match exn with
| :? AggregateException as aex -> aex.InnerExceptions |> Seq.toList |> Some
| _ -> None

#endif

/// <summary>
/// Safely dispose a resource (includes null-checking).
Expand All @@ -1667,7 +1695,7 @@ module Operators =
let dispose (resource: System.IDisposable) = match resource with null -> () | x -> x.Dispose ()


#if !FABLE_COMPILER
#if !FABLE_COMPILER

/// <summary>Additional operators for Arrows related functions which shadows some F# operators for bitwise functions.</summary>
module Arrows =
Expand All @@ -1688,4 +1716,4 @@ module Operators =
/// <category index="24">Arrow Functions</category>
let inline (|||) (f: '``ArrowChoice<'T,'V>``) (g: '``ArrowChoice<'U,'V>``) : '``ArrowChoice<Choice<'U,'T>,'V>`` = Fanin.Invoke f g

#endif
#endif
5 changes: 0 additions & 5 deletions tests/FSharpPlus.Tests/Task.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ module Task =
open FSharpPlus.Tests.Helpers

exception TestException of string

let (|AggregateException|_|) (x: exn) =
match x with
| :? AggregateException as e -> e.InnerExceptions |> Seq.toList |> Some
| _ -> None

module TaskTests =

Expand Down
5 changes: 0 additions & 5 deletions tests/FSharpPlus.Tests/ValueTask.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ module ValueTask =
open FSharpPlus.Tests.Helpers

exception TestException of string

let (|AggregateException|_|) (x: exn) =
match x with
| :? AggregateException as e -> e.InnerExceptions |> Seq.toList |> Some
| _ -> None

type ValueTask<'T> with
static member WhenAll (source: ValueTask<'T> seq) = source |> Seq.map (fun x -> x.AsTask ()) |> Task.WhenAll |> ValueTask<'T []>
Expand Down
Loading