Skip to content

Instantly share code, notes, and snippets.

@paulp
Created February 8, 2014 17:48
Show Gist options
  • Save paulp/8887410 to your computer and use it in GitHub Desktop.
Save paulp/8887410 to your computer and use it in GitHub Desktop.
// zip two lists, call map, function types inferred
scala> SafeList(1, 2, 3, 4) zip SafeList[Double](1, 2, 3, 4) map (_ + _)
res0: psp.core.Foreach[Double] = 2.0 :: 4.0 :: 6.0 :: 8.0 :: Nil
// zip three lists, call map, function types inferred
scala> SafeList(1, 2, 3, 4) zip SafeList[Double](1, 2, 3, 4) zip SafeList[Long](1, 2, 3, 4) map (_ + _ + _)
res1: psp.core.Foreach[Double] = 3.0 :: 6.0 :: 9.0 :: 12.0 :: Nil
// Arity mismatch - compile time error
scala> SafeList(1, 2, 3, 4) zip SafeList[Double](1, 2, 3, 4) zip SafeList[Long](1, 2, 3) map (_ + _ + _)
<console>:18: error: type mismatch;
found : psp.core.SafeList.L3[Long]
required: psp.core.SafeList[psp.core.SafeList._4,?]
// Three tails on list of length three, okay
scala> SafeList(1, 2, 3).tail.tail.tail
res3: psp.core.SafeList[psp.core.SafeList._3#Prev#Prev#Prev,Int] = Nil
// Tail on empty list - compile time error
scala> SafeList(1, 2, 3).tail.tail.tail.tail
<console>:18: error: type mismatch;
found : psp.core.SafeList[psp.core.SafeList._3#Prev#Prev#Prev,Int]
required: ?{def tail: ?}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment