Skip to content

Instantly share code, notes, and snippets.

@nelanka
Last active March 17, 2016 22:20
Show Gist options
  • Save nelanka/eb3b1b3685ef88276620 to your computer and use it in GitHub Desktop.
Save nelanka/eb3b1b3685ef88276620 to your computer and use it in GitHub Desktop.
Scala Enumerations
object ActionType extends Enumeration {
type ActionType = Value
val GET = Value("Get")
val SET = Value("Set")
implicit def stringToActionType(action: String): ActionType = action match {
case "Get" => GET
case "Set" => SET
}
}
sealed trait Market
case object HongKong extends Market
case object Singapore extends Market
case object NewYork extends Market
case object Tokyo extends Market
case object Other extends Market
def makeMarket(m: String) = m match {
case "HongKong" => HongKong
case "Singapore" => Singapore
case "NewYork" => NewYork
case "Tokyo" => Tokyo
case _ => Other
}
sealed abstract class SideAndShort(val side: Byte, val shortSell: Byte)
case object Buy extends SideAndShort('B', ' ')
case object Sell extends SideAndShort('S', ' ')
case object SellShort extends SideAndShort('S', '1')
case object SellShortExempt extends SideAndShort('S', '1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment