Add Iterable.once to ccompat
This commit is contained in:
parent
1612950702
commit
17a986792c
2 changed files with 35 additions and 1 deletions
|
|
@ -9,9 +9,12 @@
|
|||
|
||||
package org.apache.pekko.util
|
||||
|
||||
import org.apache.pekko.util.OptionConverters._
|
||||
import org.apache.pekko
|
||||
import pekko.util.ccompat._
|
||||
import pekko.util.OptionConverters._
|
||||
|
||||
import java.util._
|
||||
import scala.annotation.nowarn
|
||||
|
||||
/**
|
||||
* These tests are here to ensure that methods from [[org.apache.pekko.util.FutureConverters]], [[org.apache.pekko.util.OptionConverters]]
|
||||
|
|
@ -20,6 +23,9 @@ import java.util._
|
|||
*
|
||||
* Remove this once Scala 2.12 support is dropped since all methods are in Scala 2.13+ stdlib
|
||||
*/
|
||||
|
||||
@ccompatUsedUntil213
|
||||
@nowarn("msg=deprecated")
|
||||
object Scala212CompatTest {
|
||||
|
||||
// .toJavaPrimitive tests
|
||||
|
|
@ -57,4 +63,8 @@ object Scala212CompatTest {
|
|||
OptionConverters.toJava(OptionConverters.toScala(java.util.OptionalInt.of(1)))
|
||||
OptionConverters.toJava(OptionConverters.toScala(java.util.OptionalLong.of(1L)))
|
||||
|
||||
// Iterable.single
|
||||
val queue = scala.collection.immutable.Queue.empty[ByteString]
|
||||
queue.enqueue(Iterable.single(ByteString.empty))
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,30 @@ package object ccompat {
|
|||
build(i.TreeMap.newBuilder[K, V], source)
|
||||
}
|
||||
|
||||
private[pekko] implicit class IterableExtensions(private val fact: Iterable.type) extends AnyVal {
|
||||
def single[A](a: A): Iterable[A] = new Iterable[A] {
|
||||
override def iterator = Iterator.single(a)
|
||||
override def sizeHintIfCheap: Int = 1
|
||||
override def hasDefiniteSize: Boolean = true
|
||||
override def head = a
|
||||
override def headOption = Some(a)
|
||||
override def last = a
|
||||
override def lastOption = Some(a)
|
||||
override def view = new IterableView[A, Iterable[A]] {
|
||||
override def iterator: Iterator[A] = Iterator.single(a)
|
||||
override def sizeHintIfCheap: Int = 1
|
||||
override def hasDefiniteSize: Boolean = true
|
||||
override protected def underlying: Iterable[A] = this
|
||||
}
|
||||
override def take(n: Int) = if (n > 0) this else Iterable.empty
|
||||
override def takeRight(n: Int) = if (n > 0) this else Iterable.empty
|
||||
override def drop(n: Int) = if (n > 0) Iterable.empty else this
|
||||
override def dropRight(n: Int) = if (n > 0) Iterable.empty else this
|
||||
override def tail = Iterable.empty
|
||||
override def init = Iterable.empty
|
||||
}
|
||||
}
|
||||
|
||||
private[pekko] implicit 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue