Advertisement
Guest User

boxed computation

a guest
Feb 25th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.37 KB | None | 0 0
  1. import scala.language.implicitConversions
  2.  
  3. object Lazy {
  4.   class Lazy[T](r: => T) extends Function0[T] {
  5.     lazy val result = r
  6.  
  7.     def apply(): T = {
  8.       result
  9.     }
  10.    
  11.     // This doesn't work...
  12.     // def `match`[R](body: T => R):R = {result match body}
  13.   }
  14.  
  15.   implicit def unbox[T](box: Lazy[T]): T = box()
  16.   def apply[T](r: => T) = new Lazy(r)
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement