Founctors与Monad

Founctor(函子)

函子包含以下定义:

  • 包装了另一种类型,就像 Array<T>Optional<T>,它们都包装了 T 类型。
  • 有一个函数签名为 (T->U) -> Type<U>map 方法。

Monad(单子)

  • 是一个函子(包含了内部类型 T 并且拥有 map 方法)。
  • 同时有函数签名为 (T -> Type<U>) -> Type<U>flatMap 方法。

http://swift.gg/2015/10/30/lets-talk-about-monads/


参考

Let's talk about Monads