language-ext v3.3.19 Release Notes

Release Date: 2019-08-21 // over 2 years ago
  • Reader

    The Reader monad now has more advanced error handling (which is also reflected in the code-gen that wraps the Reader monad).

    ๐Ÿšš This means Reader<Env, A>.Run(env) now returns ReaderResult<A> instead of TryOption<A>. I have also removed Filter and Where from Reader and instead you should use:

    from x in success? Reader\<Env, A\>(successValue) : ReaderFail\<Env, A\>("Fail message") ...
    

    Filter and Where would return a result in a Bottom state, which isn't ideal. Obviously if you need this functionality back then you can create the extension methods yourself to create a similar functionality:

    public static Reader\<Env, A\> Where\<Env, A\>(this Reader\<Env, A\> ma, Func\<A, bool\> f) =\>ma.Bind(a =\> f(a) ? Reader\<Env, A\>(a) : ReaderFail\<Env, A\>(BottomException.Default));
    

    Fail states can be created using:

    ReaderFail\<Env, A\>(string message); ReaderFail\<Env, A\>(string message, Exception exception); ReaderFail\<Env, A\>(Exception exception);
    

    ReaderResult

    ReaderResult<A> has Match and IfNone (so replace previous usage of IfNoneOrFail with IfNone). It also has conversion methods: ToSeq(), ToList(), ToOption(), ToOptionUnsafe(), ToOptionAsync(), ToEither(), ToEither(Func<Error, L> f), ToEitherUnsafe(), ToEitherUnsafe(Func<Error, L> f), ToEitherAsync(), ToEitherAsync(Func<Error, L> f), ToTry(), ToTryAsync()

    Error

    ๐Ÿ‘ป To facilitate the better error handling I needed to add a new Error type. The chances of this clashing with user's code is large, so it has been put into a new namespace: LanguageExt.Common. It can hold a message, a status value int, and an Exception.

    Result

    ๐Ÿ‘€ It seems to me that Result, OptionalResult, and Error belong in the same namespace so Result and OptionalResult have been moved to LanguageExt.Common.

    ๐Ÿ‘€ On the whole you shouldn't really see Error or Result, most of the time you'll just be doing member access - and so the need to include the LanguageExt.Common should be rare.