blob: 4f803c07f8624d48f2e397de2196d52a4a3790b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package ixee.cryptopals.utils
import ixee.cryptopals.utils.FunctionUtils._
object StreamUtils {
implicit class RichStream[A](x: Stream[A]) {
def splice(other: Stream[A]): Stream[A] =
spliceEvery(1)(other)
def spliceEvery(n: Int)(other: Stream[A]): Stream[A] =
x.grouped(n).zip(other.iterator).flatMap(tup(_ :+ _)).to[Stream]
def continually: Stream[A] =
x append x.continually
}
def continuous[A](xs: Seq[A]): Stream[A] =
xs.to[Stream] append continuous(xs.to[Stream])
/*
// Or just xs.to[Stream] ...
def fromSeq[A](xs: Seq[A]): Stream[A] =
xs.foldLeft(Stream.empty[A])(_ :+ _)
*/
}
|