Last active
December 15, 2015 07:38
-
-
Save ahoy-jon/5224356 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SomeHelper { | |
implicit def lazyFunc[A,B](f: A=> B): ((=> A) => B) = a => f(a) | |
} | |
object MyApp extends App { | |
import SomeHelper._ | |
val m = new SomeFunctor(1) | |
val g: (Int) => String = x => sys.error("g raise an error") | |
val f: (=> String) => Boolean = x => try { x; true } catch { case e: Throwable => false } | |
m.map(x => f(g(x))).foreach(println) | |
m.map(g).map(x => f(x)).foreach(println) | |
} | |
class SomeFunctor[A](a: => A) { | |
def map[B](f: (=> A) => B):SomeFunctor[B] = new SomeFunctor(f(a)) | |
def foreach(f: A => Unit):Unit = f(a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment