Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelocenerine committed Oct 27, 2017
1 parent 31634d0 commit c7d7600
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class HashSetBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class ImmutableArrayBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class LazyListBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class ListBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.util.concurrent.TimeUnit

import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import strawman.collection.Tuple2Zipped

import scala.{Any, AnyRef, Int, Long, Unit, math}
import scala.Predef.intWrapper
Expand Down Expand Up @@ -183,6 +182,12 @@ class NumericRangeBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Int, b: Int) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.util.concurrent.TimeUnit

import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import strawman.collection.Tuple2Zipped

import scala.{Any, AnyRef, Int, Long, Unit, math}
import scala.Predef.intWrapper
Expand Down Expand Up @@ -183,6 +182,12 @@ class RangeBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Int, b: Int) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class ScalaHashSetBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ class ScalaListBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class ScalaTreeSetBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ class ScalaVectorBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class TreeSetBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class VectorBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class ArrayBufferBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ class ListBufferBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ class ScalaArrayBenchmark {
@Benchmark
def transform_zip(bh: Blackhole): Unit = bh.consume(xs.zip(xs))

@Benchmark
def transform_zipMapTupled(bh: Blackhole): Unit = {
val f = (a: Long, b: Long) => (a, b)
bh.consume(xs.zip(xs).map(f.tupled))
}

@Benchmark
def transform_zipWithIndex(bh: Blackhole): Unit = bh.consume(xs.zipWithIndex)

Expand Down
25 changes: 2 additions & 23 deletions collections/src/main/scala/strawman/collection/Iterable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package strawman
package collection

import scala.annotation.unchecked.uncheckedVariance
import scala.language.implicitConversions
import scala.reflect.ClassTag
import scala.{Any, Array, Boolean, `inline`, Int, None, Numeric, Option, Ordering, PartialFunction, StringContext, Some, Unit, deprecated, IllegalArgumentException, Function1, AnyRef}
import java.lang.{String, UnsupportedOperationException}
Expand Down Expand Up @@ -1004,29 +1005,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] {
}

object Iterable extends IterableFactory.Delegate[Iterable](immutable.Iterable) {

implicit class LazyZipOps[A, C1[X] <: Iterable[X]](`this`: C1[A]) {

/** Analogous to `zip` except that the elements in each collection are not consumed until a strict operation is
* invoked on the returned `Tuple2Zipped` decorator.
*
* Calls to `lazyZip` can be chained to support higher arities (up to 4) without incurring the expense of
* constructing and deconstructing intermediary tuples.
*
* {{{
* val xs = $Coll(1, 2, 3)
* val res = (xs lazyZip xs lazyZip xs lazyZip xs).map((a, b, c, d) => a + b + c + d)
* // res == $Col(4, 8, 12)
* }}}
*
* @param that the iterable providing the second half of each eventual pair
* @tparam B the type of the element in the second half of each eventual pair
* @tparam C2 the type of `that` iterable
* @return a decorator `Tuple2Zipped` that allows strict operations to be performed on the lazily evaluated pairs
* or chained calls to `lazyZip`. Implicit conversion to `Iterable[(A, B)]` is also supported.
*/
def lazyZip[B, C2[X] <: Iterable[X]](that: C2[B]): Tuple2Zipped[A, C1[A], B, C2[B]] = new Tuple2Zipped(`this`, that)
}
implicit def toLazyZipOps[A, CC[X] <: Iterable[X]](that: CC[A]): LazyZipOps[A, CC[A]] = new LazyZipOps(that)
}

abstract class AbstractIterable[+A] extends Iterable[A]
Loading

0 comments on commit c7d7600

Please sign in to comment.