Skip to content

Commit a931844

Browse files
committed
+ Active Pattern for AggregateException
1 parent e38e549 commit a931844

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
@@ -1659,7 +1659,7 @@ module Operators =
16591659
/// <category index="23">Additional Functions</category>
16601660
let inline (|Parsed|_|) str : 'T option = tryParse str
16611661

1662-
#endif
1662+
#endif
16631663

16641664
/// <summary>
16651665
/// An active pattern to match strings in a case-insensitive way.
@@ -1673,14 +1673,29 @@ module Operators =
16731673
| s when s.Equals(ciString, StringComparison.OrdinalIgnoreCase) -> Some ()
16741674
| _ -> None
16751675

1676+
#if !FABLE_COMPILER
1677+
1678+
/// <summary>
1679+
/// An active pattern to match AggregateException and extract its inner exceptions as a list.
1680+
/// </summary>
1681+
/// <category index="23">Additional Functions</category>
1682+
let (|AggregateException|_|) (exn: exn) : exn list option =
1683+
let exn = nullArgCheck (nameof exn) exn
1684+
1685+
match exn with
1686+
| :? AggregateException as aex -> aex.InnerExceptions |> Seq.toList |> Some
1687+
| _ -> None
1688+
1689+
#endif
1690+
16761691
/// <summary>
16771692
/// Safely dispose a resource (includes null-checking).
16781693
/// </summary>
16791694
/// <category index="23">Additional Functions</category>
16801695
let dispose (resource: System.IDisposable) = match resource with null -> () | x -> x.Dispose ()
16811696

16821697

1683-
#if !FABLE_COMPILER
1698+
#if !FABLE_COMPILER
16841699

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

1704-
#endif
1719+
#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
@@ -10,11 +10,6 @@ module ValueTask =
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
type ValueTask<'T> with
2015
static member WhenAll (source: ValueTask<'T> seq) = source |> Seq.map (fun x -> x.AsTask ()) |> Task.WhenAll |> ValueTask<'T []>

0 commit comments

Comments
 (0)