Created
June 11, 2017 17:11
-
-
Save pedrovgs/15957e12061016c501086e2e13f43ca3 to your computer and use it in GitHub Desktop.
Declaration of a wrap function using Scala.
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
type Text = Option[String] | |
case class ColumnWidth(width: Int) | |
sealed trait WrapError | |
case class InvalidText(text: Text) extends WrapError | |
case class InvalidColumnWidth(width: ColumnWidth) extends WrapError | |
def wrap(text: Text, width: ColumnWidth): Either[WrapError, Text] = ??? | |
def foo(): Unit = { | |
val text = Some("Hello!") | |
val columnWidth = ColumnWidth(1) | |
val result = wrap(text, columnWidth) | |
result match { | |
case Left(InvalidText(text)) => ??? | |
case Left(InvalidColumnWidth(width)) => ??? | |
case Right(Some(text)) => ??? | |
case _ => ??? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment