Skip to content

Instantly share code, notes, and snippets.

@retronym
Created June 27, 2010 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/454818 to your computer and use it in GitHub Desktop.
Save retronym/454818 to your computer and use it in GitHub Desktop.
scala> import scalaz._; import Scalaz._
import scalaz._
import Scalaz._
scala> val t1 = (1, 2, 3)
t1: (Int, Int, Int) = (1,2,3)
scala> val t2 = (1, "a", false)
t2: (Int, java.lang.String, Boolean) = (1,a,false)
scala> t1 mapAll()
res0: (Int, Int, Int) = (1,2,3)
scala> t1 mapAll(_1 = 1+)
res1: (Int, Int, Int) = (2,2,3)
scala> t1 mapAll(_2 = 1+)
res2: (Int, Int, Int) = (1,3,3)
scala> t2 copy(_2 = "b")
res3: (Int, java.lang.String, Boolean) = (1,b,false)
scala> t2 copy(_2 = 0.5)
res4: (Int, Double, Boolean) = (1,0.5,false)
scala> t1 toIndexedSeq
res5: IndexedSeq[Int] = Vector(1, 2, 3)
scala> t2.toIndexedSeq
res6: IndexedSeq[Any] = Vector(1, a, false)
scala> (1, 2) mapAll(_ * 2, _ * 3)
res7: (Int, Int) = (2,6)
scala> t2 fold (_.toString + _ + _.toString)
res8: java.lang.String = 1afalse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment