Skip to content

Instantly share code, notes, and snippets.

View seanparsons's full-sized avatar
💭
Setting A Status Message

Sean Parsons seanparsons

💭
Setting A Status Message
View GitHub Profile
@seanparsons
seanparsons / FirstSome.scala
Last active December 14, 2015 15:19 — forked from channingwalton/FirstSome.scala
Cunning use of monoids with Function1.
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>
@seanparsons
seanparsons / SKI_Applicative.scala
Created August 2, 2012 09:06 — forked from tonymorris/SKI_Applicative.scala
Applicative Functor / SKI combinator calculus
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
@seanparsons
seanparsons / validateanyProduct.scala
Created May 31, 2012 15:23 — forked from wfaler/validateanyProduct.scala
validateanyProduct.scala
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