What is the difference between a monad and a closure?

后端 未结 4 1055
别跟我提以往
别跟我提以往 2021-02-08 11:24

i am kinda confused reading the definition between the two. Can they actually intersect in terms of definition? or am i completely lost? Thanks.

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-08 12:02

    Closures, as the word tends to be used, are just functions (or blocks of code, if you like) that you can treat like a piece of data and pass to other functions, etc. (the "closed" bit is that wherever you eventually call it, it behaves just as it would if you called it where it was originally defined). A monad is (roughly) more like a context in which functions can be chained together sequentially, and controls how data is passed from one function to the next.

提交回复
热议问题