Skip to content

Instantly share code, notes, and snippets.

View Keybase.md

Keybase proof

I hereby claim:

  • I am merkury on github.
  • I am merkury (https://keybase.io/merkury) on keybase.
  • I have a public key whose fingerprint is 642B 4068 E13A 3B28 DE47 4E6E C085 7B55 AFFA F463

To claim this, I am signing this object:

View 1-Functor-and-Monad.md

Copy and paste the swift code below into a playground to experiment.

This is a very close emulation of Functor and Monad typeclasses in swift. As of Swift 1.2 and Xcode 6.3, this is no longer very fragile.

Unfortunately, the compiler cannot verify the types when passing a function to (>>=). We have to wrap the function in a closure and call it with an explicit argument to compile.

optionalDoubles >>= squareRoot // doesn't compile
optionalDoubles >>= { squareRoot($0) } // compiles