Skip to content

Instantly share code, notes, and snippets.

View wolfendale's full-sized avatar

Michael Wolfendale wolfendale

View GitHub Profile
@wolfendale
wolfendale / forms.scala
Created November 13, 2015 13:30
Play Framework Boolean Formatter
implicit val booleanFormatter: Formatter[Boolean] = new Formatter[Boolean] {
override val format = Some(("format.boolean", Nil))
override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], Boolean] =
data.get(key) match {
case Some(value) => value match {
case "true" => Right(true)
case "false" => Right(false)
case _ => Left(Seq(FormError(key, "error.boolean", Nil)))
@wolfendale
wolfendale / FromStringMap.scala
Created October 31, 2015 23:42
Map[String, String] to Case Class
package wolfendale
import shapeless._
import shapeless.labelled._
import scala.util.{Failure, Success, Try}
trait FromStringMap[A] {
def apply(data: Map[String, String]): Try[A]
}