alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (Alpha.scala)

This example Scala source code file (Alpha.scala) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

alpha, alphainstances, char

The Alpha.scala Scala example source code

package scalaz

/** An algebraic data type representing the characters 'a' to 'z' */
sealed abstract class Alpha extends Product with Serializable {
  val toChar: Char

  def toUpperChar: Char = toChar.toUpper
}

object Alpha extends AlphaInstances {

  case object A extends Alpha {
    val toChar = 'a'
  }

  case object B extends Alpha {
    val toChar = 'b'
  }

  case object C extends Alpha {
    val toChar = 'c'
  }

  case object D extends Alpha {
    val toChar = 'd'
  }

  case object E extends Alpha {
    val toChar = 'e'
  }

  case object F extends Alpha {
    val toChar = 'f'
  }

  case object G extends Alpha {
    val toChar = 'g'
  }

  case object H extends Alpha {
    val toChar = 'h'
  }

  case object I extends Alpha {
    val toChar = 'i'
  }

  case object J extends Alpha {
    val toChar = 'j'
  }

  case object K extends Alpha {
    val toChar = 'k'
  }

  case object L extends Alpha {
    val toChar = 'l'
  }

  case object M extends Alpha {
    val toChar = 'm'
  }

  case object N extends Alpha {
    val toChar = 'n'
  }

  case object O extends Alpha {
    val toChar = 'o'
  }

  case object P extends Alpha {
    val toChar = 'p'
  }

  case object Q extends Alpha {
    val toChar = 'q'
  }

  case object R extends Alpha {
    val toChar = 'r'
  }

  case object S extends Alpha {
    val toChar = 's'
  }

  case object T extends Alpha {
    val toChar = 't'
  }

  case object U extends Alpha {
    val toChar = 'u'
  }

  case object V extends Alpha {
    val toChar = 'v'
  }

  case object W extends Alpha {
    val toChar = 'w'
  }

  case object X extends Alpha {
    val toChar = 'x'
  }

  case object Y extends Alpha {
    val toChar = 'y'
  }

  case object Z extends Alpha {
    val toChar = 'z'
  }

  val alphas: List[Alpha] = List(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

  implicit def ToCharFromAlpha(a: Alpha): Char = a.toChar

}

sealed abstract class AlphaInstances {
  // TODO
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Alpha.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.