Skip to content

Commit fca8b0d

Browse files
gustywallymathieu
authored andcommitted
+ Active Pattern for AggregateException
1 parent b2d1d46 commit fca8b0d

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

‎src/FSharpPlus/Operators.fs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ module Operators =
16761676
/// <category index="23">Additional Functions</category>
16771677
let inline (|Parsed|_|) str : 'T option = tryParse str
16781678

1679-
#endif
1679+
#endif
16801680

16811681
/// <summary>
16821682
/// An active pattern to match strings in a case-insensitive way.
@@ -1690,14 +1690,29 @@ module Operators =
16901690
| s when s.Equals(ciString, StringComparison.OrdinalIgnoreCase) -> Some ()
16911691
| _ -> None
16921692

1693+
#if !FABLE_COMPILER
1694+
1695+
/// <summary>
1696+
/// An active pattern to match AggregateException and extract its inner exceptions as a list.
1697+
/// </summary>
1698+
/// <category index="23">Additional Functions</category>
1699+
let (|AggregateException|_|) (exn: exn) : exn list option =
1700+
let exn = nullArgCheck (nameof exn) exn
1701+
1702+
match exn with
1703+
| :? AggregateException as aex -> aex.InnerExceptions |> Seq.toList |> Some
1704+
| _ -> None
1705+
1706+
#endif
1707+
16931708
/// <summary>
16941709
/// Safely dispose a resource (includes null-checking).
16951710
/// </summary>
16961711
/// <category index="23">Additional Functions</category>
16971712
let dispose (resource: System.IDisposable) = match resource with null -> () | x -> x.Dispose ()
16981713

16991714

1700-
#if (!FABLE_COMPILER || FABLE_COMPILER_3) && !FABLE_COMPILER_4
1715+
#if (!FABLE_COMPILER || FABLE_COMPILER_3) && !FABLE_COMPILER_4
17011716

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

1721-
#endif
1736+
#endif

‎tests/FSharpPlus.Tests/Task.fs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ module Task =
1010
open FSharpPlus.Tests.Helpers
1111

1212
exception TestException of string
13-
14-
let (|AggregateException|_|) (x: exn) =
15-
match x with
16-
| :? AggregateException as e -> e.InnerExceptions |> Seq.toList |> Some
17-
| _ -> None
1813

1914
module TaskTests =
2015

‎tests/FSharpPlus.Tests/ValueTask.fs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ module ValueTask =
1212
open FSharpPlus.Tests.Helpers
1313

1414
exception TestException of string
15-
16-
let (|AggregateException|_|) (x: exn) =
17-
match x with
18-
| :? AggregateException as e -> e.InnerExceptions |> Seq.toList |> Some
19-
| _ -> None
2015

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

0 commit comments

Comments
 (0)