Last active
October 8, 2022 11:39
-
-
Save mcalavera81/5aeb70e53f32966e57d2d69d3bddb5fb 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
case class Event(name: String, start: Int, end: Int) | |
def validateName(name: String): Option[String] = | |
if (name.size > 0) Some(name) else None | |
def validateEnd(end: Int): Option[Int] = | |
if (end < 3000) Some(end) else None | |
def validateStart(start: Int, end: Int): Option[Int] = | |
if (start <= end) Some(start) else None | |
def parse(name: String, | |
start: Int, end: Int): Option[Event] = | |
for { | |
validName <- validateName(name) | |
validEnd <- validateEnd(end) | |
validStart <- validateStart(start, end) | |
} yield Event(validName, validStart, validEnd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment