Monads with Java 8

前端 未结 9 1029
礼貌的吻别
礼貌的吻别 2020-12-07 07:29

In the interests of helping to understand what a monad is, can someone provide an example using java ? Are they possible ?

Lambda expressions are possible using java

9条回答
  •  有刺的猬
    2020-12-07 08:28

    Despite all controversy about Optional satisfying, or not, the Monad laws, I usually like to look at Stream, Optional and CompletableFuture in the same way. In truth, all them provide a flatMap() and that is all I care and let me embrace the "the tasteful composition of side effects" (cited by Erik Meijer). So we may have corresponding Stream, Optional and CompletableFuture in the following way:

    Regarding Monads, I usually simplify it only thinking on flatMap()(from "Principles of Reactive Programming" course by Erik Meijer):

    Eric-Meijer-flatMap

提交回复
热议问题