Skip to content

Instantly share code, notes, and snippets.

@stasimus
Created October 9, 2018 21:16
Show Gist options
  • Save stasimus/3953d2504c2c00de916a4cd7ff02f1a5 to your computer and use it in GitHub Desktop.
Save stasimus/3953d2504c2c00de916a4cd7ff02f1a5 to your computer and use it in GitHub Desktop.
/* From Scala
trait M[A] { def flatMap[B](f: A => M[B]): M[B] }
def unit[A](x: A): M[A]
*/
fun <A> A.unit(): A? = this
fun <A, B> A?.flatMap(func: (A) -> B?): B? =
if (this != null) func(this) else null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment