May. 13th, 2010

juan_gandhi: (Default)
Steve Jobs: "If you want porn buy an Android"

Fuck you Steve. I'll buy an Android. (I wonder what makes people write "by" instead of "buy")
juan_gandhi: (Default)
  case class LazyPair[X, Y](_1: X, f: X => Y) extends Product2[X, Y]
  {
    private lazy val y = f(_1)
    override def toString() = "(" + _1 + "," + _2 + ")"
    override def _2 = y
  }

  def lazyPair[X, Y](x: X, f: X => Y): Product2[X, Y] = new LazyPair(x, f)



The idea is, we won't call the function until we actually need it; and do it only once.

Note there's no variance in type parameters. I really do not know what to do about it, since the right variance would be [-X,+Y], and it does look stupid, no? Or maybe it does not.

Since it is case class, basically that's all we need.

Scala class Pair is actually Tuple2 which has tons of methods. I've lately came to a conclusion that we do not need most of the methods in most of the classes - e.g. Set[T] does not need size... and many other methods. Only have the right stuff.

Well, whatever. Just asking for your opinion.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Nov. 15th, 2025 10:31 am
Powered by Dreamwidth Studios