This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def validateProduct[T <: Product](product: T): Seq[String] = product.productIterator.flatMap{value => value match { | |
case null => Seq("null attributes are not allowed for " + product) | |
case string: String if (string.isEmpty) => Seq("Empty strings are not allowed for " + product) | |
case innerProduct: Product => validateProduct(innerProduct) | |
case _ => Seq() | |
}}.toSeq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SKI_Applicative { | |
/* | |
First, let's talk about the SK combinator calculus and how it contributes to solving your problem. | |
The SK combinator calculus is made of two functions (aka combinators): S and K. It is sometimes called the SKI combinator calculus, | |
however, the I combinator can be derived from S and K. The key observation of SK is that it is a turing-complete system and therefore, | |
anything that can be expressed as SK is also turing-complete. Here is a demonstration that Scala's type system is turing-complete | |
(and therefore, undecidable) for example[1]. | |
The K combinator is the most trivial of the two. It is sometimes called "const" (as in Haskell). There is also some discussion about |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import scalaz._,Scalaz._ | |
import scalaz._ | |
import Scalaz._ | |
scala> val isOne = (i: Int) => {println("isOne"); if (i == 1) Some(1) else None} | |
isOne: Int => Option[Int] = <function1> | |
scala> val isTwo = (i: Int) => {println("isTwo"); if (i == 2) Some(2) else None} | |
isTwo: Int => Option[Int] = <function1> |