Skip to content

Instantly share code, notes, and snippets.

package ca.yk.gov.cfs.fm.common
import scala.util.matching.Regex
object rules {
sealed trait ValidatorOp[A]
object ValidatorOp {
final case class Definition[A](fieldName: String, rules: RuleOp[A]) extends ValidatorOp[A]
package ca.yk.gov.cfs.fm.common
object validators {
import rules._
val centreCodeRule: RuleOp[String] = nonEmpty && maxLength(10)
val accountCodeOp: ValidatorOp[String] = define("ACCOUNT_CODE", nonEmpty && maxLength(22))
val billingCentreCodeOp: ValidatorOp[String] = define("BILLING_CODE", centreCodeRule || startsWith("B"))
val orderNumberPrefixOp: ValidatorOp[String] = define("ORDER_NUMBER_PREFIX", (nonEmpty && maxLength(2)) || pattern("^[a-zA-Z]+$".r))
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()