Skip to content

Instantly share code, notes, and snippets.

@emmettna
Last active January 20, 2020 04:27
Show Gist options
  • Save emmettna/851a251abb6d3a7e878e3a4172357f7d to your computer and use it in GitHub Desktop.
Save emmettna/851a251abb6d3a7e878e3a4172357f7d to your computer and use it in GitHub Desktop.
val five = 5
five match {
case v if v > 5 => ???
case v if v == 5 => ???
case v if v < 5 => ???
}
// more practical example
final case class FeeInquiry(user: UserId, amount: BigDecimal, currency: Currency)
val requestedFee: Option[FeeInquiry] = ???
requestedFee match {
case Some(FeeInquiry(user, amount, currency) if currency === Currency.USD =>
Right(amount)
case Some(FeeInquiry(user, amount, currency) if currency === Currency.__ =>
Left("We can't accept other than USD")
case None => Right(BigDecimal(0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment