Answer the question
In order to leave comments, you need to log in
What is a monad?
Trying to understand what a monad is. Dictionary definition:
it is an abstraction of a linear chain of related computations
Streams are Monads that play a big role in enabling functional programming in Java.
Answer the question
In order to leave comments, you need to log in
Here, a simple explanation - https://urvanov.ru/2017/10/18/%D0%BC%D0%BE%D0%BD%D...
A monad is an abstraction over a chain of related computations. A container that takes the current state and a function that takes that state as an argument and returns the new state. This container encapsulates the environment (context) for performing calculations, taking into account possible exceptions; the output is only the expected values. In general, just a monoid in the category of endofunctors (c).
There is a usual calculation a -> b
. Monads implement calculations with effects:
Maybe - there may be failure,
List - many results,
Either - typed exceptions,
(s, b) - writing to the log,
( (->) e ) b - reading from external environment,
(State s) b - mutable states,
IO b - I/O (console, files).
(examples for Haskel)
A monad is a common interface that allows you to work with very different entities in a unified way, such as lists, parsers, IO operations (both synchronous and asynchronous).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question