Commit 697115d4 authored by Alexander Gehrke's avatar Alexander Gehrke
Browse files

Allow keeping the separating line in List.split

parent b85d7457
......@@ -2,15 +2,15 @@ package aoc2020.lib
/* for splitting input with separator lines */
extension [A](input: List[A])(using Eql[A,A])
def split(separator: A): LazyList[List[A]] =
def split(separator: A, keepSeparator: Boolean = false): LazyList[List[A]] =
input.span(_ != separator) match {
case (h, _ :: t) => h #:: t.split(separator)
case (Nil, Nil) => LazyList()
case (h, Nil) => LazyList(h)
case (Nil, Nil) => LazyList()
case (h, Nil) => LazyList(h)
case (h, tail as (_ :: t)) =>
h #:: (if keepSeparator then tail else t).split(separator)
}
/* Using -Yexplicit-nulls isn't really ready for use with the java standard
* library. e.g. String doesn't have `@NotNull` annotations
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment