Skip to content

Commit f06e14b

Browse files
authored
Merge pull request #1310 from julienrf/update-collections-architecture-213RC1
Update collections architecture to 2.13.0-RC1
2 parents 898139b + e6c3ab6 commit f06e14b

File tree

3 files changed

+113
-97
lines changed

3 files changed

+113
-97
lines changed

_overviews/core/architecture-of-scala-213-collections.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,39 +280,39 @@ implementations of `filter` and `map`:
280280
trait IterableOps[+A, +CC[_], +C] {
281281

282282
def filter(pred: A => Boolean): C =
283-
fromSpecificIterable(new View.Filter(this, pred))
283+
fromSpecific(new View.Filter(this, pred))
284284

285285
def map[B](f: A => B): CC[B] =
286-
fromIterable(new View.Map(this, f))
286+
from(new View.Map(this, f))
287287

288-
protected def fromSpecificIterable(coll: Iterable[A]): C
289-
protected def fromIterable[E](it: Iterable[E]): CC[E]
288+
protected def fromSpecific(coll: IterableOnce[A]): C
289+
protected def from[E](it: IterableOnce[E]): CC[E]
290290
}
291291
~~~
292292

293293
Let’s detail the implementation of `filter`, step by step:
294294

295295
- the instantiation of `View.Filter` creates a (non-strict) `View` that filters the elements
296296
of the underlying collection ;
297-
- the call to `fromSpecificIterable` turns the `View` into a concrete
298-
collection `C`. The implementation of `fromSpecificIterable` is left to
297+
- the call to `fromSpecific` turns the `View` into a concrete
298+
collection `C`. The implementation of `fromSpecific` is left to
299299
concrete collections: they can decide to evaluate in a strict or non-strict way
300300
the elements resulting from the operation.
301301

302302
The implementation of `map` is similar, excepted that instead of using
303-
`fromSpecificIterable` it uses `fromIterable` which takes as parameter an
303+
`fromSpecific` it uses `from` which takes as parameter an
304304
iterable whose element type `E` is arbitrary.
305305

306-
Actually, `fromIterable` is not abstract in `IterableOps`: it delegates to an
307-
`iterableFactory` member (which is abstract):
306+
Actually, the `from` operation is not defined directly in `IterableOps` but is accessed via
307+
an (abstract) `iterableFactory` member:
308308

309309
~~~ scala
310310
trait IterableOps[+A, +CC[_], +C] {
311311

312-
protected def fromIterable[E](it: Iterable[E]): CC[E] =
313-
iterableFactory.from(it)
314-
315312
def iterableFactory: IterableFactory[CC]
313+
314+
def map[B](f: A => B): CC[B] =
315+
iterableFactory.from(new View.Map(this, f))
316316

317317
}
318318
~~~
@@ -336,12 +336,9 @@ trait MapOps[K, +V, +CC[_, _], +C]
336336
extends IterableOps[(K, V), Iterable, C] {
337337

338338
def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2, V2] =
339-
mapFromIterable(new View.Map(this, f))
340-
341-
// Similar to fromIterable, but returns a Map collection type
342-
protected def mapFromIterable[K2, V2](it: Iterable[(K2, V2)]): CC[K2, V2] =
343-
mapFactory.from(it)
339+
mapFactory.from(new View.Map(this, f))
344340

341+
// Similar to iterableFactory, but for Map collection types
345342
def mapFactory: MapFactory[CC]
346343

347344
}
@@ -387,7 +384,7 @@ type of elements. The following code shows the relevant parts of `IterableOps` a
387384
~~~ scala
388385
trait IterableOps[+A, +CC[_], +C] {
389386
def iterableFactory: IterableFactory[CC]
390-
protected def fromSpecificIterable(coll: Iterable[A]): C
387+
protected def fromSpecific(coll: IterableOnce[A]): C
391388
protected def newSpecificBuilder: Builder[A, C]
392389
}
393390

@@ -428,3 +425,10 @@ This document explains that:
428425

429426
You now have all the required knowledge to implement
430427
[custom collection types]({{ site.baseurl }}/overviews/core/custom-collections.html).
428+
429+
### Acknowledgement ###
430+
431+
This page contains material adapted from the book
432+
[Programming in Scala](http://www.artima.com/shop/programming_in_scala) by
433+
Odersky, Spoon and Venners. We thank Artima for graciously agreeing to its
434+
publication.

_overviews/core/custom-collection-operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ trait BuildFrom[-From, -A, +C] {
279279
/** @return a collection of type `C` containing the same elements
280280
* (of type `A`) as the source collection `it`.
281281
*/
282-
def fromSpecificIterable(from: From)(it: Iterable[A]): C
282+
def fromSpecific(from: From)(it: IterableOnce[A]): C
283283

284284
/** @return a Builder for the collection type `C`, containing
285285
* elements of type `A`.

0 commit comments

Comments
 (0)