Skip to content

Commit ba77e2f

Browse files
authored
Merge pull request #6 from julienrf/stream-lazy-append-all
Add lazyAppendAll alias to append in Stream
2 parents 144d86e + a5acd1e commit ba77e2f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/scala-2.12/collection/compat/package.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ package object compat {
4444
def fromSpecific(source: TraversableOnce[Int]): C = fact.apply(source.toSeq: _*)
4545
}
4646

47+
implicit class StreamExtensionMethods[A](private val stream: Stream[A]) extends AnyVal {
48+
def lazyAppendAll(as: => TraversableOnce[A]): Stream[A] = stream.append(as)
49+
}
50+
4751
// This really belongs into scala.collection but there's already a package object in scala-library so we can't add to it
4852
type IterableOnce[+X] = TraversableOnce[X]
4953
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package collection
2+
3+
import org.junit.Test
4+
5+
import scala.collection.compat._
6+
7+
class StreamTest {
8+
9+
@Test
10+
def lazyAppendAll(): Unit = {
11+
val s = 1 #:: 2 #:: 3 #:: Stream.Empty
12+
s.lazyAppendAll(List(4, 5, 6))
13+
}
14+
15+
}

0 commit comments

Comments
 (0)