Skip to content

Commit f193b1d

Browse files
committed
+ Active Pattern for AggregateException
1 parent 10b12ef commit f193b1d

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/FSharpPlus/Operators.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,18 @@ module Operators =
16731673
| s when s.Equals(ciString, StringComparison.InvariantCultureIgnoreCase) -> Some ()
16741674
| _ -> None
16751675

1676+
/// <summary>
1677+
/// An active pattern to match AggregateException and extract its inner exceptions as a list.
1678+
/// </summary>
1679+
/// <category index="23">Additional Functions</category>
1680+
let (|AggregateException|_|) (exn: exn) : exn list option =
1681+
let exn = nullArgCheck (nameof exn) exn
1682+
1683+
match exn with
1684+
| :? AggregateException as aex -> aex.InnerExceptions |> Seq.toList |> Some
1685+
| _ -> None
1686+
1687+
16761688
/// <summary>
16771689
/// Safely dispose a resource (includes null-checking).
16781690
/// </summary>

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)