@@ -12,7 +12,7 @@ import cats.instances.vector._
12
12
* `NonEmptyVector`. However, due to https://issues.scala-lang.org/browse/SI-6601, on
13
13
* Scala 2.10, this may be bypassed due to a compiler bug.
14
14
*/
15
- final class NonEmptyVector [A ] private (val toVector : Vector [A ]) extends AnyVal {
15
+ final class NonEmptyVector [+ A ] private (val toVector : Vector [A ]) extends AnyVal {
16
16
17
17
/** Gets the element at the index, if it exists */
18
18
def get (i : Int ): Option [A ] =
@@ -22,15 +22,15 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
22
22
def getUnsafe (i : Int ): A = toVector(i)
23
23
24
24
/** Updates the element at the index, if it exists */
25
- def updated (i : Int , a : A ): Option [NonEmptyVector [A ]] =
25
+ def updated [ AA >: A ] (i : Int , a : AA ): Option [NonEmptyVector [AA ]] =
26
26
if (toVector.isDefinedAt(i)) Some (new NonEmptyVector (toVector.updated(i, a))) else None
27
27
28
28
/**
29
29
* Updates the element at the index, or throws an `IndexOutOfBoundsException`
30
30
* if none exists (if `i` does not satisfy `0 <= i < length`).
31
31
*/
32
- def updatedUnsafe (i : Int , a : A ):
33
- NonEmptyVector [A ] = new NonEmptyVector (toVector.updated(i, a))
32
+ def updatedUnsafe [ AA >: A ] (i : Int , a : AA ):
33
+ NonEmptyVector [AA ] = new NonEmptyVector (toVector.updated(i, a))
34
34
35
35
def head : A = toVector.head
36
36
@@ -63,37 +63,37 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
63
63
/**
64
64
* Alias for [[concat ]]
65
65
*/
66
- def ++ (other : Vector [A ]): NonEmptyVector [A ] = concat(other)
66
+ def ++ [ AA >: A ] (other : Vector [AA ]): NonEmptyVector [AA ] = concat(other)
67
67
68
68
/**
69
69
* Append another `Vector` to this, producing a new `NonEmptyVector`.
70
70
*/
71
- def concat (other : Vector [A ]): NonEmptyVector [A ] = new NonEmptyVector (toVector ++ other)
71
+ def concat [ AA >: A ] (other : Vector [AA ]): NonEmptyVector [AA ] = new NonEmptyVector (toVector ++ other)
72
72
73
73
/**
74
74
* Append another `NonEmptyVector` to this, producing a new `NonEmptyVector`.
75
75
*/
76
- def concatNev (other : NonEmptyVector [A ]): NonEmptyVector [A ] = new NonEmptyVector (toVector ++ other.toVector)
76
+ def concatNev [ AA >: A ] (other : NonEmptyVector [AA ]): NonEmptyVector [AA ] = new NonEmptyVector (toVector ++ other.toVector)
77
77
78
78
/**
79
79
* Append an item to this, producing a new `NonEmptyVector`.
80
80
*/
81
- def append (a : A ): NonEmptyVector [A ] = new NonEmptyVector (toVector :+ a)
81
+ def append [ AA >: A ] (a : AA ): NonEmptyVector [AA ] = new NonEmptyVector (toVector :+ a)
82
82
83
83
/**
84
84
* Alias for [[append ]]
85
85
*/
86
- def :+ (a : A ): NonEmptyVector [A ] = append(a)
86
+ def :+ [ AA >: A ] (a : AA ): NonEmptyVector [AA ] = append(a)
87
87
88
88
/**
89
89
* Prepend an item to this, producing a new `NonEmptyVector`.
90
90
*/
91
- def prepend (a : A ): NonEmptyVector [A ] = new NonEmptyVector (a +: toVector)
91
+ def prepend [ AA >: A ] (a : AA ): NonEmptyVector [AA ] = new NonEmptyVector (a +: toVector)
92
92
93
93
/**
94
94
* Alias for [[prepend ]]
95
95
*/
96
- def +: (a : A ): NonEmptyVector [A ] = prepend(a)
96
+ def +: [ AA >: A ] (a : AA ): NonEmptyVector [AA ] = prepend(a)
97
97
98
98
/**
99
99
* Find the first element matching the predicate, if one exists
@@ -137,13 +137,13 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
137
137
/**
138
138
* Left-associative reduce using f.
139
139
*/
140
- def reduceLeft (f : (A , A ) => A ): A =
141
- tail.foldLeft(head)(f)
140
+ def reduceLeft [ AA >: A ] (f : (AA , AA ) => AA ): AA =
141
+ tail.foldLeft(head : AA )(f)
142
142
143
143
/**
144
144
* Reduce using the Semigroup of A
145
145
*/
146
- def reduce (implicit S : Semigroup [A ]): A =
146
+ def reduce [ AA >: A ] (implicit S : Semigroup [AA ]): AA =
147
147
S .combineAllOption(toVector).get
148
148
149
149
/**
@@ -154,7 +154,8 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
154
154
* equality provided by Eq[_] instances, rather than using the
155
155
* universal equality provided by .equals.
156
156
*/
157
- def === (that : NonEmptyVector [A ])(implicit A : Eq [A ]): Boolean = Eq [Vector [A ]].eqv(toVector, that.toVector)
157
+ def === [AA >: A ](that : NonEmptyVector [AA ])(implicit A : Eq [AA ]): Boolean =
158
+ Eq [Vector [AA ]].eqv(toVector, that.toVector)
158
159
159
160
/**
160
161
* Typesafe stringification method.
@@ -163,8 +164,8 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
163
164
* values according to Show[_] instances, rather than using the
164
165
* universal .toString method.
165
166
*/
166
- def show (implicit A : Show [A ]): String =
167
- s " NonEmpty ${Show [Vector [A ]].show(toVector)}"
167
+ def show [ AA >: A ] (implicit AA : Show [AA ]): String =
168
+ s " NonEmpty ${Show [Vector [AA ]].show(toVector)}"
168
169
169
170
def length : Int = toVector.length
170
171
@@ -173,11 +174,11 @@ final class NonEmptyVector[A] private (val toVector: Vector[A]) extends AnyVal {
173
174
/**
174
175
* Remove duplicates. Duplicates are checked using `Order[_]` instance.
175
176
*/
176
- def distinct (implicit O : Order [A ]): NonEmptyVector [A ] = {
177
+ def distinct [ AA >: A ] (implicit O : Order [AA ]): NonEmptyVector [AA ] = {
177
178
implicit val ord = O .toOrdering
178
179
179
- val buf = Vector .newBuilder[A ]
180
- tail.foldLeft(TreeSet (head)) { (elementsSoFar, a) =>
180
+ val buf = Vector .newBuilder[AA ]
181
+ tail.foldLeft(TreeSet (head : AA )) { (elementsSoFar, a) =>
181
182
if (elementsSoFar(a)) elementsSoFar else { buf += a; elementsSoFar + a }
182
183
}
183
184
0 commit comments