Created
February 12, 2016 03:12
-
-
Save dwijnand/f82e9477005b3157ac0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final case class MapWithTabularLite[K, V](private val xs: TraversableOnce[(K, V)]) extends AnyVal { | |
def showkv() = if (xs.nonEmpty) { | |
val len = xs.toIterator.map(_._1.toString.length).max | |
val fmt = s"%${len}s %s" | |
xs foreach (kv => println(fmt format (kv._1, kv._2))) | |
} | |
} | |
final case class MultimapWithTabularLite[K, V](private val xs: TraversableOnce[(K, TraversableOnce[V])]) extends AnyVal { | |
def showkvs() = if (xs.nonEmpty) { | |
val len = xs.toIterator.map(_._1.toString.length).max | |
val fmt = s"%${len}s %s" | |
def show(vs: TraversableOnce[V]) = if (vs.size == 1) vs.toIterator.next() else vs mkString ("[", ", ", "]") | |
xs foreach (kv => println(fmt format (kv._1, show(kv._2)))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment