Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: scala/docs.scala-lang
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5f3555382d935f942936e0d235bcff0a6f6e03a8
Choose a base ref
..
head repository: scala/docs.scala-lang
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a3843679d0f7ff2dff43a73466ceec762949ca11
Choose a head ref
Showing with 6 additions and 6 deletions.
  1. +6 −6 _overviews/core/custom-collection-operations.md
12 changes: 6 additions & 6 deletions _overviews/core/custom-collection-operations.md
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ println(users.sumBy(_.age)) // “42”
We can define the `sumBy` operation as an extension method, using an
[implicit class](/overviews/core/implicit-classes.html), so that it can be called like a method:

```tut
~~~ scala
import scala.collection.IterableOnce

implicit class SumByOperation[A](coll: IterableOnce[A]) {
@@ -53,7 +53,7 @@ implicit class SumByOperation[A](coll: IterableOnce[A]) {
result
}
}
```
~~~

Unfortunately, this extension method does not work with values of type `String` and not
even with `Array`. This is because these types are not part of the Scala collections
@@ -193,7 +193,7 @@ In practice, it is recommended to [not eagerly evaluate the elements of the coll

Finally, here is how we can implement a generator of arbitrary collection types:

```tut
~~~ scala
import scala.collection.Factory

implicit def collection[CC[_], A](implicit
@@ -210,7 +210,7 @@ implicit def collection[CC[_], A](implicit
factory.fromSpecific(lazyElements)
}
}
```
~~~

The implementation uses a lazy source collection of a random size (`lazyElements`).
Then it calls the `fromSpecific` method of the `Factory` to build the collection
@@ -236,7 +236,7 @@ a `String` we want to get back another `String`, and so on.
Building on what we’ve learned from the previous sections, we can start defining an extension method
using `IsSeq` and producing a collection by using an implicit `Factory`:

```tut
~~~ scala
import scala.collection.{ AbstractIterator, AbstractView, Factory, SeqOps }
import scala.collection.generic.IsSeq

@@ -258,7 +258,7 @@ class IntersperseOperation[A](seqOps: SeqOps[A, Iterable, _]) {

implicit def IntersperseOperation[Repr](coll: Repr)(implicit seq: IsSeq[Repr]): IntersperseOperation[seq.A] =
new IntersperseOperation(seq(coll))
```
~~~

However, if we try it we get the following behaviour: