On Sat, May 26, 2012 at 12:42:44PM +0200, Jason Zaugg wrote:
> On Sat, May 26, 2012 at 12:38 PM, wookietreiber
> <kizkizz...@googlemail.com> wrote:
> > Hi there,
> >
> > I'd like Scala to better support tuple syntax, consider the following
> > example:
> >
> >> $ scala
> >> Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_03-icedtea).
> >> Type in expressions to have them evaluated.
> >> Type :help for more information.
> >>
> >> scala> (0 to 5).zipWithIndex map { (a,b) => a*b } foreach println
> >> <console>:8: error: wrong number of parameters; expected = 1
> >> (0 to 5).zipWithIndex map { (a,b) => a*b } foreach println
>
> You can destructure function arguments with a pattern matching
> anonymous function:
>
> scala> (0 to 5).zipWithIndex map { case (a,b) => a*b }
> res1: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 1, 4, 9, 16, 25)
Doesn't this introduce some performance overhead, that goes along with
pattern matching or will that get optimized away?
>
> -jason
--
Beste Grüße / Best Regards
Doesn't this introduce some performance overhead, that goes along withOn Sat, May 26, 2012 at 12:42:44PM +0200, Jason Zaugg wrote:
> On Sat, May 26, 2012 at 12:38 PM, wookietreiber
> <kizkizz...@googlemail.com> wrote:
> > Hi there,
> >
> > I'd like Scala to better support tuple syntax, consider the following
> > example:
> >
> >> $ scala
> >> Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_03-icedtea).
> >> Type in expressions to have them evaluated.
> >> Type :help for more information.
> >>
> >> scala> (0 to 5).zipWithIndex map { (a,b) => a*b } foreach println
> >> <console>:8: error: wrong number of parameters; expected = 1
> >> (0 to 5).zipWithIndex map { (a,b) => a*b } foreach println
>
> You can destructure function arguments with a pattern matching
> anonymous function:
>
> scala> (0 to 5).zipWithIndex map { case (a,b) => a*b }
> res1: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 1, 4, 9, 16, 25)
pattern matching or will that get optimized away?
>
> -jason
--
Beste Grüße / Best Regards