Saturday, July 23, 2016

Scala enumerations

http://underscore.io/blog/posts/2014/09/03/enumerations.html

https://gist.github.com/chaotic3quilibrium/57add1cd762eb90f6b24

http://stackoverflow.com/questions/1898932/case-objects-vs-enumerations-in-scala

http://stackoverflow.com/questions/17646335/combining-enums-and-using-getter-to-return-a-specified-enum

http://jackcoughonsoftware.blogspot.rs/2008/06/scala-and-enums.html

http://stackoverflow.com/questions/26492941/scala-enumeration-with-constructor-and-lookup-table

http://stackoverflow.com/questions/4346580/how-to-add-a-method-to-enumeration-in-scala
object Suit extends Enumeration {
   val Clubs, Diamonds, Hearts, Spades = Value

   class SuitValue(suit: Value) {
      def isRed = !isBlack
      def isBlack = suit match {
         case Clubs | Spades => true
         case _              => false
      }
   }

   implicit def value2SuitValue(suit: Value) = new SuitValue(suit)
} 
object Direction extends Enumeration {
type Direction = Value
val NORTH, SOUTH, EAST, WEST = Value
}
import Direction._
var value: Set[Direction.Value] = Set[Direction.Value](Direction.NORTH, Direction.SOUTH)