Skip to content

Commit

Permalink
Set all classes final
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed Sep 5, 2024
1 parent 0208593 commit 7eaa94b
Showing 1 changed file with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,75 +360,75 @@ private[compat] trait PackageShared {
new RandomExtensions(self)
}

class ArrayExtensions(private val fact: Array.type) extends AnyVal {
final class ArrayExtensions(private val fact: Array.type) extends AnyVal {
def from[A: ClassTag](source: TraversableOnce[A]): Array[A] =
source match {
case it: Iterable[A] => it.toArray[A]
case _ => source.toIterator.toArray[A]
}
}

class ImmutableSortedMapExtensions(private val fact: i.SortedMap.type) extends AnyVal {
final class ImmutableSortedMapExtensions(private val fact: i.SortedMap.type) extends AnyVal {
def from[K: Ordering, V](source: TraversableOnce[(K, V)]): i.SortedMap[K, V] =
build(i.SortedMap.newBuilder[K, V], source)
}

class ImmutableListMapExtensions(private val fact: i.ListMap.type) extends AnyVal {
final class ImmutableListMapExtensions(private val fact: i.ListMap.type) extends AnyVal {
def from[K, V](source: TraversableOnce[(K, V)]): i.ListMap[K, V] =
build(i.ListMap.newBuilder[K, V], source)
}

class ImmutableHashMapExtensions(private val fact: i.HashMap.type) extends AnyVal {
final class ImmutableHashMapExtensions(private val fact: i.HashMap.type) extends AnyVal {
def from[K, V](source: TraversableOnce[(K, V)]): i.HashMap[K, V] =
build(i.HashMap.newBuilder[K, V], source)
}

class ImmutableTreeMapExtensions(private val fact: i.TreeMap.type) extends AnyVal {
final class ImmutableTreeMapExtensions(private val fact: i.TreeMap.type) extends AnyVal {
def from[K: Ordering, V](source: TraversableOnce[(K, V)]): i.TreeMap[K, V] =
build(i.TreeMap.newBuilder[K, V], source)
}

class ImmutableIntMapExtensions(private val fact: i.IntMap.type) extends AnyVal {
final class ImmutableIntMapExtensions(private val fact: i.IntMap.type) extends AnyVal {
def from[V](source: TraversableOnce[(Int, V)]): i.IntMap[V] =
build(i.IntMap.canBuildFrom[Int, V](), source)
}

class ImmutableLongMapExtensions(private val fact: i.LongMap.type) extends AnyVal {
final class ImmutableLongMapExtensions(private val fact: i.LongMap.type) extends AnyVal {
def from[V](source: TraversableOnce[(Long, V)]): i.LongMap[V] =
build(i.LongMap.canBuildFrom[Long, V](), source)
}

class MutableLongMapExtensions(private val fact: m.LongMap.type) extends AnyVal {
final class MutableLongMapExtensions(private val fact: m.LongMap.type) extends AnyVal {
def from[V](source: TraversableOnce[(Long, V)]): m.LongMap[V] =
build(m.LongMap.canBuildFrom[Long, V](), source)
}

class MutableHashMapExtensions(private val fact: m.HashMap.type) extends AnyVal {
final class MutableHashMapExtensions(private val fact: m.HashMap.type) extends AnyVal {
def from[K, V](source: TraversableOnce[(K, V)]): m.HashMap[K, V] =
build(m.HashMap.canBuildFrom[K, V](), source)
}

class MutableListMapExtensions(private val fact: m.ListMap.type) extends AnyVal {
final class MutableListMapExtensions(private val fact: m.ListMap.type) extends AnyVal {
def from[K, V](source: TraversableOnce[(K, V)]): m.ListMap[K, V] =
build(m.ListMap.canBuildFrom[K, V](), source)
}

class MutableMapExtensions(private val fact: m.Map.type) extends AnyVal {
final class MutableMapExtensions(private val fact: m.Map.type) extends AnyVal {
def from[K, V](source: TraversableOnce[(K, V)]): m.Map[K, V] =
build(m.Map.canBuildFrom[K, V](), source)
}

class StreamExtensionMethods[A](private val stream: Stream[A]) extends AnyVal {
final class StreamExtensionMethods[A](private val stream: Stream[A]) extends AnyVal {
def lazyAppendedAll(as: => TraversableOnce[A]): Stream[A] = stream.append(as)
}

class SortedExtensionMethods[K, T <: Sorted[K, T]](private val fact: Sorted[K, T]) {
final class SortedExtensionMethods[K, T <: Sorted[K, T]](private val fact: Sorted[K, T]) {
def rangeFrom(from: K): T = fact.from(from)
def rangeTo(to: K): T = fact.to(to)
def rangeUntil(until: K): T = fact.until(until)
}

class SortedMapExtensionMethods[K, V](
final class SortedMapExtensionMethods[K, V](
private val self: collection.SortedMap[K, V]
) extends AnyVal {

Expand All @@ -437,7 +437,7 @@ class SortedMapExtensionMethods[K, V](
def maxBefore(key: K): Option[(K, V)] = self.until(key).lastOption
}

class SortedSetExtensionMethods[A](
final class SortedSetExtensionMethods[A](
private val self: collection.SortedSet[A]
) extends AnyVal {

Expand All @@ -446,7 +446,7 @@ class SortedSetExtensionMethods[A](
def maxBefore(key: A): Option[A] = self.until(key).lastOption
}

class IteratorExtensionMethods[A](private val self: c.Iterator[A]) extends AnyVal {
final class IteratorExtensionMethods[A](private val self: c.Iterator[A]) extends AnyVal {
def sameElements[B >: A](that: c.TraversableOnce[B]): Boolean = {
self.sameElements(that.iterator)
}
Expand All @@ -457,7 +457,7 @@ class IteratorExtensionMethods[A](private val self: c.Iterator[A]) extends AnyVa
def tapEach[U](f: A => U): c.Iterator[A] = self.map(a => { f(a); a })
}

class TraversableOnceExtensionMethods[A](private val self: c.TraversableOnce[A]) extends AnyVal {
final class TraversableOnceExtensionMethods[A](private val self: c.TraversableOnce[A]) extends AnyVal {
def iterator: Iterator[A] = self.toIterator

def minOption[B >: A](implicit ord: Ordering[B]): Option[A] = {
Expand Down Expand Up @@ -489,7 +489,7 @@ class TraversableOnceExtensionMethods[A](private val self: c.TraversableOnce[A])
}
}

class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends AnyVal {
final class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends AnyVal {
def iterableFactory: GenericCompanion[Traversable] = self.companion

def sizeCompare(otherSize: Int): Int = SizeCompareImpl.sizeCompareInt(self)(otherSize)
Expand All @@ -498,11 +498,11 @@ class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends

}

class SeqExtensionMethods[A](private val self: c.Seq[A]) extends AnyVal {
final class SeqExtensionMethods[A](private val self: c.Seq[A]) extends AnyVal {
def lengthIs: SizeCompareOps = new SizeCompareOps(self)
}

class SizeCompareOps private[compat] (private val it: c.Traversable[_]) extends AnyVal {
final class SizeCompareOps private[compat] (private val it: c.Traversable[_]) extends AnyVal {
import SizeCompareImpl._

/** Tests if the size of the collection is less than some value. */
Expand Down Expand Up @@ -564,7 +564,7 @@ private object SizeCompareImpl {
}
}

class TraversableLikeExtensionMethods[A, Repr](private val self: c.GenTraversableLike[A, Repr])
final class TraversableLikeExtensionMethods[A, Repr](private val self: c.GenTraversableLike[A, Repr])
extends AnyVal {
def tapEach[U](f: A => U)(implicit bf: CanBuildFrom[Repr, A, Repr]): Repr =
self.map(a => { f(a); a })
Expand Down Expand Up @@ -624,7 +624,7 @@ class TraversableLikeExtensionMethods[A, Repr](private val self: c.GenTraversabl
}
}

class TrulyTraversableLikeExtensionMethods[El1, Repr1](
final class TrulyTraversableLikeExtensionMethods[El1, Repr1](
private val self: TraversableLike[El1, Repr1])
extends AnyVal {

Expand All @@ -633,23 +633,23 @@ class TrulyTraversableLikeExtensionMethods[El1, Repr1](
): Tuple2Zipped[El1, Repr1, El2, Repr2] = new Tuple2Zipped((self, t2))
}

class Tuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2](
final class Tuple2ZippedExtensionMethods[El1, Repr1, El2, Repr2](
private val self: Tuple2Zipped[El1, Repr1, El2, Repr2]) {

def lazyZip[El3, Repr3, T3](t3: T3)(implicit
w3: T3 => IterableLike[El3, Repr3]): Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3] =
new Tuple3Zipped((self.colls._1, self.colls._2, t3))
}

class MapExtensionMethods[K, V](private val self: scala.collection.Map[K, V]) extends AnyVal {
final class MapExtensionMethods[K, V](private val self: scala.collection.Map[K, V]) extends AnyVal {

def foreachEntry[U](f: (K, V) => U): Unit = {
self.foreach { case (k, v) => f(k, v) }
}

}

class ImmutableMapExtensionMethods[K, V](private val self: scala.collection.immutable.Map[K, V])
final class ImmutableMapExtensionMethods[K, V](private val self: scala.collection.immutable.Map[K, V])
extends AnyVal {

def updatedWith[V1 >: V](key: K)(remappingFunction: (Option[V]) => Option[V1]): Map[K, V1] =
Expand All @@ -659,7 +659,7 @@ class ImmutableMapExtensionMethods[K, V](private val self: scala.collection.immu
}
}

class MutableMapExtensionMethods[K, V](private val self: scala.collection.mutable.Map[K, V])
final class MutableMapExtensionMethods[K, V](private val self: scala.collection.mutable.Map[K, V])
extends AnyVal {

def updateWith(key: K)(remappingFunction: (Option[V]) => Option[V]): Option[V] = {
Expand All @@ -672,7 +672,7 @@ class MutableMapExtensionMethods[K, V](private val self: scala.collection.mutabl
}
}

class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
final class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
private val self: IterableView[(K, V), C])
extends AnyVal {

Expand All @@ -693,23 +693,23 @@ class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
self.filter { case (k, _) => p(k) }
}

class ImmutableQueueExtensionMethods[A](private val self: i.Queue[A]) extends AnyVal {
final class ImmutableQueueExtensionMethods[A](private val self: i.Queue[A]) extends AnyVal {
def enqueueAll[B >: A](iter: c.Iterable[B]): i.Queue[B] =
self.enqueue(iter.to[i.Iterable])
}

class MutableQueueExtensionMethods[Element](private val self: m.Queue[Element]) extends AnyVal {
final class MutableQueueExtensionMethods[Element](private val self: m.Queue[Element]) extends AnyVal {
def enqueueAll(iter: c.Iterable[Element]): Unit =
self.enqueue(iter.toIndexedSeq: _*)
}

class OptionCompanionExtensionMethods(private val fact: Option.type) extends AnyVal {
final class OptionCompanionExtensionMethods(private val fact: Option.type) extends AnyVal {
def when[A](cond: Boolean)(a: => A): Option[A] = if (cond) Some(a) else None

@inline def unless[A](cond: Boolean)(a: => A): Option[A] = when(!cond)(a)
}

class GenericCompanionExtensionMethods[CC[X] <: GenTraversable[X]](
final class GenericCompanionExtensionMethods[CC[X] <: GenTraversable[X]](
private val companion: GenericCompanion[CC]) extends AnyVal {
def unfold[A, S](init: S)(f: S => Option[(A, S)])(
implicit cbf: CanBuildFrom[CC[A], A, CC[A]]
Expand Down

0 comments on commit 7eaa94b

Please sign in to comment.