Lately I’ve been reading a lot about functional programming principles and how they (of some of them) can be applied in C#. So I came across Language-Ext and CSharpFunctionalExtensions (as well as a few smaller ones). I briefly tried Language-Ext and am liking what I see, but haven’t tried the other. I know there’s always F#, but I want to explore other options as well.

I’d love to hear about other people’s experiences with those libraries (or similar ones). What do you like about them and what don’t you like?

  • RagingHungryPanda
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    21 days ago

    I’ve been using Language-ext and it has aspects that I do and don’t like.

    Good things:

    • Numtype and NewType. It makes it really easy to have domain IDs as proper types and making a serializer for them wasn’t difficult
    • Option type is nice to have
    • Things like Try/Async and validation functions can be useful (though not my preferred approach)
    • It tries to be efficient internally
    • It provides a good way to take a Seat of Tasks and execute them in parallel with max parallelism

    Things I don’t like:

    • It can be very opinionated at times

    • Some overloads of things may not have a result that you expect, such as putting a Task into TryAsync returns a TryAsync bc it wants Task or a lambda

    • It can be difficult to Bind between different monad types, ie Validation, Try/Async, Option/Async, etc, so many types may not get used

    • I find a common type used, EitherAsync to get pretty verbose, but you could alias if you wanted. You can’t inherit since they’re structs

    • Sometimes going between Async and sync monads isn’t as easy as you’d think

    In the past I’ve used CSharpFunctionalExtensions, which gives you Maybe and Result or Result types (no Async versions). I think I prefer the more simple signatures of this lib.

    I think I’d like to combine the domain primitives of LangExt, and Seq, with the functional extensions, and fluent validation. LangExt provides its own validation solution, so it isn’t necessary to have another one.

    LangExt does do a lot and a lot of good stuff, but it also has opinions that I’m not so sure about for csharp. Overall there’s a lot of good stuff to it. I’m not sure if I’d introduce it elsewhere, but it has done a lot for writing functional code and trying to force you into that paradigm