Created
October 13, 2015 20:57
-
-
Save colindean/9b883b93379f7c1a0e40 to your computer and use it in GitHub Desktop.
QuantityCheck - a wrapper around Seq#lengthCompare because I like matching words instead of remembering -1/0/1
This file contains hidden or 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
class QuantityCheck[T](thing: Seq[T]) | |
case class JustRight[T](thing: Seq[T]) extends QuantityCheck(thing) | |
case class TooFew[T](thing: Seq[T]) extends QuantityCheck(thing) | |
case class TooMany[T](thing: Seq[T]) extends QuantityCheck(thing) | |
object QuantityCheck { | |
def apply[T](number: Int)(seqLike: Seq[T]): QuantityCheck[T] = { | |
seqLike.lengthCompare(number) match { | |
case x if x < 0 => TooFew(seqLike) | |
case x if x == 0 => JustRight(seqLike) | |
case x if x > 0 => TooMany(seqLike) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment