0

I am using LanguageExt but I suspect the same question applies to other FP languages. I got myself in the situation below and would love to have some advice:

  • Check the value in an Option
  • Depending on the value, a different function is applied
  • The problem is that the functions return different types

How do I make this work? I am having a hard time getting the value out of the monad and apply the functions.

DavidY
  • 357
  • 5
  • 15
  • Please give us a more concrete example. – Dai Oct 01 '22 at 01:41
  • 1
    _"The problem is that the functions return different types"_ - **that's not a problem**, it just means you need to use a union-type (or a type-union... I forget) to represent the return value. – Dai Oct 01 '22 at 01:42
  • 1
    ...and LanguageExt [has loads of neat features for handling and generating unions and other types](https://github.com/louthy/language-ext#code-generation). – Dai Oct 01 '22 at 01:43
  • Thanks a lot @Dai, I will check out the union type. If that does not work out I will add more an example to the question. – DavidY Oct 01 '22 at 01:46
  • 1
    The phrase *"getting the value out of the monad"* is frequently an indication that you're trying to do something you shouldn't: https://blog.ploeh.dk/2019/02/04/how-to-get-the-value-out-of-the-monad – Mark Seemann Oct 01 '22 at 05:38

0 Answers0