Skip to content

Instantly share code, notes, and snippets.

@pedrovgs
Created June 11, 2017 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrovgs/15957e12061016c501086e2e13f43ca3 to your computer and use it in GitHub Desktop.
Save pedrovgs/15957e12061016c501086e2e13f43ca3 to your computer and use it in GitHub Desktop.
Declaration of a wrap function using Scala.
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