Skip to content

Instantly share code, notes, and snippets.

object Util {
/** Merges a collection of streams into a single stream.
*
* Returns a sorted stream if all input streams are sorted.
*/
def mergeStreams[A](streams: Traversable[Stream[A]])(implicit ord: Ordering[A]): Stream[A] = {
val streams1 = streams.toList filterNot (_.isEmpty) sortBy (_.head)
if (streams1.isEmpty)
Stream.empty
else {
@ummels
ummels / Tram-BS.md
Last active November 9, 2015 15:29
Tram Braunschweig Werbeliste

Tram Braunschweig Werbeliste

Fahrzeugliste

GT6S (AEG/LHB)

9551 grau-weiß
9552 Fliesen Winter
9553 Schwarzer Herzog/Wolters Pilsener
9554 Mc V

/** Implicit class for adding `|>` and `tap` operations to `AnyVal`.
*
* See `http://stackoverflow.com/a/11120847/839131`.
*/
implicit class PipeAndTap[A](val x: A) extends AnyVal {
/** Applies `f` to the underlying value and returns the result. */
def |>[B](f: A => B) = f(x)
/** Applies `f` to the underlying value `x` (presumably with side effects)
* and returns `x`.
val m = Map(0 -> 'a')
for (n <- 0 until 2) {
m.get(n) match {
case Some(x) => println(s"Value found for key $n: $x")
case None => println(s"No value found for key $n")
}
}