While Mathematicians like to talk non-sensical abstract idea, Informaticians want to know how to apply the idea concretely:
Monad = Monoid +Endofunctor
Monoid = Identity + Associative
Endo-functor = functor between 2 same categories
Monad is a ‘function’ to wrap the ‘side effects’ (exception errors, I/O,… ) so that function composition in ‘pipeline‘ chained operation sequence is still possible in pure FP (Functional Programming, which forbids side-effects).
Some common Monads: ‘Maybe’, ‘List’, ‘Reader’…
This allows monads to simplify a wide range of problems, like handling potential undefined values (with the
Maybe monad), or keeping values within a flexible, well-formed list (using the
List monad). With a monad, a programmer can turn a complicated sequence of functions into a succinct pipeline that abstracts away additional data management, control flow, or side-effects.
Exploring Monads in Scala Collections
1. Functional Programming:
“pure” function = no side effects
2. All applications without side effects are useless!
3. Monad wraps side-effect as if it is “pure” for FP composition.
Your choice Kotlin or Scala : (both on JVM, OO + FP)
1. If still Java-loyal but hate its verbosity, plus fancy some cool FP => Kotlin
2. If totally Haskell-like-FP convert => Scala
Functional Kotlin: map, filter, reduce, fold, lazy…
Scala vs Kotlin
Monads ~ “Design Pattern” in Functional Programming
Examples: “Option”, “Some”,…
Monoid = an Algebraic structure (“Algebra” ) with: Associativity & Identity
Monad = Monoid + Endo-Functors
Scala is a non-pure FP (Functional Programming) language with the Object-oriented feature, unlike the pure FP such as Haskell or Clojure (Lisp). It is popular in Android platform as an alternative to Java.