LanguageExt.Core

LanguageExt.Core Prelude Catch

Contents

class Prelude Source #

The @catch functions produce a CatchError or CatchValue type. These can be composed together with the Aff and Eff monads (and maybe more in the future), to create a functional-programming equivalent to exception catching and matching.

Examples

 public class TimeoutExample<RT>
     where RT : struct,
     HasTime<RT>,
     HasCancel<RT>,
     HasConsole<RT>
 {
     public static Eff<RT, Unit> main =>
         from _1 in timeout(60 * seconds, longRunning)
                  | @catch(Errors.TimedOut, unitEff)
         from _2 in Console<RT>.writeLine("done")
         select unit;

     static Aff<RT, Unit> longRunning =>
         (from tm in Time<RT>.now
          from _1 in Console<RT>.writeLine(tm.ToLongTimeString())
          select unit)
        .ToAff()
        .Repeat(Schedule.Fibonacci(1 * second));
 }

Methods

method CatchM<Error, M, A> catchOf <E, M, A> (Func<E, K<M, A>> Fail) Source #

where E : Error
where M : Fallible<Error, M>, Monad<M>

Catch all Error errors of subtype E and return Fail

method CatchM<Error, M, A> catchOfFold <E, M, A> (Func<E, K<M, A>> Fail) Source #

where E : Error
where M : Fallible<Error, M>, MonoidK<M>

Catch all Error errors of subtype E and return Fail

method CatchM<Error, M, A> @catch <M, A> (Error error, Func<Error, K<M, A>> Fail) Source #

where M : Fallible<Error, M>

Catch an error if the error matches the argument provided

method CatchM<Error, M, A> @catch <M, A> (Error error, K<M, A> Fail) Source #

where M : Fallible<Error, M>

Catch an error if the error matches the argument provided

method CatchM<Error, M, A> @catch <M, A> (int errorCode, Func<Error, K<M, A>> Fail) Source #

where M : Fallible<Error, M>

Catch an error if the error matches the argument provided

method CatchM<Error, M, A> @catch <M, A> (int errorCode, K<M, A> Fail) Source #

where M : Fallible<Error, M>

Catch an error if the error matches the argument provided

method CatchM<Error, M, A> @catch <M, A> (Func<Error, bool> predicate, Func<Error, K<M, A>> Fail) Source #

where M : Fallible<Error, M>

Catch an error if the error matches the argument provided

method CatchM<Error, M, A> @catch <M, A> (Func<Error, bool> predicate, K<M, A> Fail) Source #

where M : Fallible<Error, M>

Catch an error if the error matches the argument provided

method CatchM<Error, M, A> @catch <M, A> (Func<Error, K<M, A>> Fail) Source #

where M : Fallible<Error, M>

Catch all errors and return Fail

method CatchM<Error, M, A> @catch <M, A> (K<M, A> Fail) Source #

where M : Fallible<Error, M>

Catch all errors and return Fail

method CatchM<Error, M, A> expected <M, A> (Func<Expected, K<M, A>> Fail) Source #

where M : Fallible<Error, M>, Monad<M>

Catch all Expected errors and return Fail

method CatchM<Error, M, A> expectedOf <E, M, A> (Func<E, K<M, A>> Fail) Source #

where E : Expected
where M : Fallible<Error, M>, Monad<M>

Catch all Expected errors of subtype E and return Fail

method CatchM<Error, M, A> exceptional <M, A> (Func<Exceptional, K<M, A>> Fail) Source #

where M : Fallible<Error, M>, Monad<M>

Catch all Exceptional errors and return Fail

method CatchM<Error, M, A> exceptionalOf <E, M, A> (Func<E, K<M, A>> Fail) Source #

where E : Exceptional
where M : Fallible<Error, M>, Monad<M>

Catch all errors and return Fail

method CatchM<Error, M, A> expectedFold <M, A> (Func<Expected, K<M, A>> Fail) Source #

where M : Fallible<Error, M>, MonoidK<M>

Catch all Expected errors and return Fail

method CatchM<Error, M, A> expectedOfFold <E, M, A> (Func<E, K<M, A>> Fail) Source #

where E : Expected
where M : Fallible<Error, M>, MonoidK<M>

Catch all Expected errors of subtype E and return Fail

method CatchM<Error, M, A> exceptionalFold <M, A> (Func<Exceptional, K<M, A>> Fail) Source #

where M : Fallible<Error, M>, MonoidK<M>

Catch all Exceptional errors and return Fail

method CatchM<Error, M, A> exceptionalOfFold <E, M, A> (Func<E, K<M, A>> Fail) Source #

where E : Exceptional
where M : Fallible<Error, M>, MonoidK<M>

Catch all errors and return Fail

class Prelude Source #

The @catch functions produce a CatchError or CatchValue type. These can be composed together with the Aff and Eff monads (and maybe more in the future), to create a functional-programming equivalent to exception catching and matching.

Examples

 public class TimeoutExample<RT>
     where RT : struct,
     HasTime<RT>,
     HasCancel<RT>,
     HasConsole<RT>
 {
     public static Eff<RT, Unit> main =>
         from _1 in timeout(60 * seconds, longRunning)
                  | @catch(Errors.TimedOut, unitEff)
         from _2 in Console<RT>.writeLine("done")
         select unit;

     static Aff<RT, Unit> longRunning =>
         (from tm in Time<RT>.now
          from _1 in Console<RT>.writeLine(tm.ToLongTimeString())
          select unit)
        .ToAff()
        .Repeat(Schedule.Fibonacci(1 * second));
 }

Methods

method CatchM<E, M, A> @catch <E, M, A> (E error, Func<E, K<M, A>> Fail) Source #

where M : Fallible<E, M>

Catch an error if the error matches the argument provided

method CatchM<E, M, A> @catch <E, M, A> (E error, K<M, A> Fail) Source #

where M : Fallible<E, M>

Catch an error if the error matches the argument provided

method CatchM<E, M, A> @catch <E, M, A> (Func<E, bool> predicate, Func<E, K<M, A>> Fail) Source #

where M : Fallible<E, M>

Catch an error if the error matches the argument provided

method CatchM<E, M, A> @catch <E, M, A> (Func<E, bool> predicate, K<M, A> Fail) Source #

where M : Fallible<E, M>

Catch an error if the error matches the argument provided

method CatchM<E, M, A> @catch <E, M, A> (Func<E, K<M, A>> Fail) Source #

where M : Fallible<E, M>

Catch all errors and return Fail