Skip to content

Commit 7c4a776

Browse files
authored
Merge pull request #1 from Ichoran/wip/cc2-cipt-internal-ev
Moved `Ev` from a generic type parameter to a member type in CIPT.
2 parents 9f58c61 + a873a39 commit 7c4a776

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/main/scala/strawman/collection/Iterable.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@ trait IterablePolyTransforms[+A, +C[A]] extends Any {
201201
/** Transforms over iterables that can return collections of different element types for which an
202202
* implicit evidence is required.
203203
*/
204-
trait ConstrainedIterablePolyTransforms[+A, +C[A], +CC[X] <: C[X], Ev[A]] extends ConstrainedFromIterable[CC, Ev] with IterablePolyTransforms[A, C] {
204+
trait ConstrainedIterablePolyTransforms[+A, +C[A], +CC[X] <: C[X]] extends IterablePolyTransforms[A, C] {
205+
type Ev[A]
205206

206207
protected def coll: Iterable[A]
208+
protected def constrainedFromIterable[B: Ev](it: Iterable[B]): CC[B]
207209

208210
/** Map */
209211
def map[B : Ev](f: A => B): CC[B] = constrainedFromIterable(View.Map(coll, f))
@@ -218,6 +220,11 @@ trait ConstrainedIterablePolyTransforms[+A, +C[A], +CC[X] <: C[X], Ev[A]] extend
218220
def zip[B](xs: IterableOnce[B])(implicit ev: Ev[(A @uncheckedVariance, B)]): CC[(A @uncheckedVariance, B)] = constrainedFromIterable(View.Zip(coll, xs))
219221
// sound bcs of VarianceNote
220222

223+
def collect[B: Ev](pf: scala.PartialFunction[A, B]): CC[B] = flatMap(a =>
224+
if (pf.isDefinedAt(a)) View.Elems(pf(a))
225+
else View.Empty
226+
)
227+
221228
/** Widen this collection to the most specific unconstrained collection type. */
222229
def unconstrained: C[A @uncheckedVariance]
223230
}

src/main/scala/strawman/collection/SortedSet.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ trait SortedSet[A]
1010

1111
trait SortedSetLike[A, +C[X] <: SortedSet[X]]
1212
extends SortedLike[A, C[A]]
13-
with ConstrainedIterablePolyTransforms[A, Set, SortedSet, Ordering]
13+
with ConstrainedIterablePolyTransforms[A, Set, SortedSet]
1414
with SetLike[A, Set] // Inherited Set operations return a `Set`
15-
with SetMonoTransforms[A, C[A]] // Override the return type of Set ops to return C[A]
15+
with SetMonoTransforms[A, C[A]]// Override the return type of Set ops to return C[A]
16+
{
17+
type Ev[A] = Ordering[A]
18+
}

src/main/scala/strawman/collection/immutable/SortedSet.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trait SortedSet[A]
1313

1414
trait SortedSetLike[A, +C[X] <: SortedSet[X]]
1515
extends collection.SortedSetLike[A, C]
16-
with ConstrainedIterablePolyTransforms[A, Set, C, Ordering]
16+
with ConstrainedIterablePolyTransforms[A, Set, C]
1717
with SetLike[A, Set] // Inherited Set operations return a `Set`
1818
with SetMonoTransforms[A, C[A]] // Override the return type of Set ops to return C[A]
19+

src/main/scala/strawman/collection/mutable/SortedSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ trait SortedSet[A]
1212

1313
trait SortedSetLike[A, +C[X] <: SortedSet[X]]
1414
extends collection.SortedSetLike[A, C]
15-
with ConstrainedIterablePolyTransforms[A, Set, SortedSet, Ordering]
15+
with ConstrainedIterablePolyTransforms[A, Set, SortedSet]
1616
with SetLike[A, Set]
1717
with SetMonoTransforms[A, C[A]]

0 commit comments

Comments
 (0)