3

Can someone explain the concept of Monad in Arrow functional programming?

https://arrow-kt.io/docs/datatypes/option/

MLProgrammer-CiM
  • 17,231
  • 5
  • 42
  • 75
Sujin Shrestha
  • 1,203
  • 2
  • 13
  • 23

1 Answers1

6

Here's a good explanation from the documentation:

In Arrow terms, a Monad is an interface with two operations: a constructor just, and flatMap

Arrow provides both documentation for Monad and a longer Monad Explanation.

In a short and very non-academic way, though, Monad can be viewed as a design pattern to safely chain calls. If you used Stream API in Java, you've used monads. If you've used promises in JavaScript, you've used monads.

Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40
  • 3
    …if you've `map`ped and `concat`enated arrays, you've used monads. And thousands more. – Bergi Sep 10 '18 at 11:52
  • 2
    @Bergi, though it may be confusing to the OP, `map` is actually part of `Functor`, not `Monad`. And `concat` isn't really either (though it can be implemented in terms of `Monad`). But this may be getting too pedantic. – melston Sep 11 '18 at 23:48
  • @melston `flatMap` = `map` + `join`, where `join` is `concat` on arrays. Is there a `concatMap` method in Kotlin? – Bergi Sep 12 '18 at 13:29