Skip to content

Commit cdbd9ff

Browse files
committed
split more
1 parent be5b172 commit cdbd9ff

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/FSharpPlus/Control/Monad.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ type TryWith =
206206
static member inline TryWith (_: unit -> ^t when ^t: null and ^t: struct, _ : exn -> 't , _: Default1, _) = ()
207207

208208
static member TryWith (computation: unit -> seq<_> , catchHandler: exn -> seq<_> , _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e))
209-
static member TryWith (computation: unit -> FSharpPlus.Data.NonEmptySeq<_>, catchHandler: exn -> FSharpPlus.Data.NonEmptySeq<_>, _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e)) |> FSharpPlus.Data.NonEmptySeq.unsafeOfSeq
209+
static member TryWith (computation: unit -> NonEmptySeq<_>, catchHandler: exn -> NonEmptySeq<_>, _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e)) |> NonEmptySeq.unsafeOfSeq
210210
static member TryWith (computation: unit -> 'R -> _ , catchHandler: exn -> 'R -> _ , _: Default2, _) = (fun s -> try (computation ()) s with e -> catchHandler e s) : 'R ->_
211211
static member TryWith (computation: unit -> Async<_> , catchHandler: exn -> Async<_> , _: TryWith , _) = async.TryWith ((computation ()), catchHandler)
212212
#if !FABLE_COMPILER
@@ -218,6 +218,10 @@ type TryWith =
218218
let inline call (mthd: 'M, input: unit -> 'I, _output: 'R, h: exn -> 'I) = ((^M or ^I) : (static member TryWith : _*_*_*_ -> _) input, h, mthd, False)
219219
call (Unchecked.defaultof<TryWith>, (fun () -> source), Unchecked.defaultof<'``Monad<'T>``>, f)
220220

221+
static member inline InvokeFromOtherMonad (source: unit ->'``Monad<'T>``) (f: exn -> '``Monad<'T>``) : '``Monad<'T>`` =
222+
let inline call (mthd: 'M, input: unit -> 'I, _output: 'R, h: exn -> 'I) = ((^M or ^I) : (static member TryWith : _*_*_*_ -> _) input, h, mthd, True)
223+
call (Unchecked.defaultof<TryWith>, source, Unchecked.defaultof<'``Monad<'T>``>, f)
224+
221225
static member inline InvokeForWhile (source: '``Monad<'T>``) (f: exn -> '``Monad<'T>``) : '``Monad<'T>`` =
222226
let inline call (mthd: 'M, input: unit -> 'I, _output: 'R, h: exn -> 'I) = ((^M or ^I) : (static member TryWith : _*_*_*_ -> _) input, h, mthd, While)
223227
call (Unchecked.defaultof<TryWith>, (fun () -> source), Unchecked.defaultof<'``Monad<'T>``>, f)
@@ -237,7 +241,7 @@ type TryWithS =
237241
static member inline TryWith (_: unit -> ^t when ^t: null and ^t: struct, _ : exn -> 't , _: Default1, _) = ()
238242

239243
static member TryWith (computation: unit -> seq<_> , catchHandler: exn -> seq<_> , _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e))
240-
static member TryWith (computation: unit -> FSharpPlus.Data.NonEmptySeq<_>, catchHandler: exn -> FSharpPlus.Data.NonEmptySeq<_>, _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e)) |> FSharpPlus.Data.NonEmptySeq.unsafeOfSeq
244+
static member TryWith (computation: unit -> NonEmptySeq<_>, catchHandler: exn -> NonEmptySeq<_>, _: Default2, _) = seq (try (Seq.toArray (computation ())) with e -> Seq.toArray (catchHandler e)) |> NonEmptySeq.unsafeOfSeq
241245
static member TryWith (computation: unit -> 'R -> _ , catchHandler: exn -> 'R -> _ , _: Default2, _) = (fun s -> try (computation ()) s with e -> catchHandler e s) : 'R ->_
242246
static member TryWith (computation: unit -> Async<_> , catchHandler: exn -> Async<_> , _: TryWithS, _) = async.TryWith ((computation ()), catchHandler)
243247
#if !FABLE_COMPILER

src/FSharpPlus/Data/Reader.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ type ReaderT<'r, 'monad, 't> with
220220
static member inline Zip (x: ReaderT<'S, 'Monad, 'T>, y: ReaderT<'S, 'Monad, 'U>) = ReaderT.zip x y
221221

222222
static member inline TryWith (source: ReaderT<'R, 'Monad, 'T>, f: exn -> ReaderT<'R, 'Monad, 'T>) =
223-
ReaderTOperations.ReaderT<'``Monad<'T>``, 'Monad, 'R, 'T> (fun s -> TryWithS.Invoke (fun () -> (ReaderT.run source s : '``Monad<'T>``)) (fun x -> ReaderT.run (f x) s))
223+
ReaderTOperations.ReaderT<'``Monad<'T>``, 'Monad, 'R, 'T> (fun s -> TryWith.InvokeFromOtherMonad (fun () -> (ReaderT.run source s : '``Monad<'T>``)) (fun x -> ReaderT.run (f x) s))
224224

225225
static member inline TryFinally (computation: ReaderT<'R, 'Monad, 'T>, f) =
226226
ReaderTOperations.ReaderT<'``Monad<'T>``, 'Monad, 'R, 'T> (fun s -> TryFinallyS.Invoke (fun () -> ReaderT.run computation s) f)

src/FSharpPlus/Data/State.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ type StateT<'s, 'monad, 't> with
234234
static member inline Zip (x: StateT<'S, 'Monad, 'T>, y: StateT<'S, 'Monad, 'U>) = StateT.zip x y
235235

236236
static member inline TryWith (source: StateT<'S, 'Monad, 'T>, f: exn -> StateT<'S, 'Monad, 'T>) =
237-
StateTOperations.StateT< '``Monad<'T * 'S>``, 'Monad, 'S, 'T> (fun s -> TryWithS.Invoke (fun () -> (StateT.run source s : '``Monad<'T * 'S>`` )) (fun x -> StateT.run (f x) s))
237+
StateTOperations.StateT< '``Monad<'T * 'S>``, 'Monad, 'S, 'T> (fun s -> TryWith.InvokeFromOtherMonad (fun () -> (StateT.run source s : '``Monad<'T * 'S>`` )) (fun x -> StateT.run (f x) s))
238238

239239
static member inline TryFinally (computation: StateT<'S,'Monad,'T>, f) =
240240
StateTOperations.StateT< '``Monad<'T * 'S>``, 'Monad, 'S, 'T> (fun s -> TryFinallyS.Invoke (fun () -> StateT.run computation s) f)

0 commit comments

Comments
 (0)