Created
October 11, 2017 18:18
-
-
Save gabfssilva/e2a8b3838771b3a5aace350ce7a3c408 to your computer and use it in GitHub Desktop.
type classes
This file contains hidden or 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
private object Validations { | |
trait NotEmpty[F[_], T] { | |
def validate(field: F[T]): Boolean | |
} | |
implicit def optionNotEmpty[T]: NotEmpty[Option, T] = field => field.isDefined | |
implicit def listNotEmpty[T]: NotEmpty[List, T] = field => field.nonEmpty | |
def notEmpty[F[_], T](field: F[T])(implicit ev: NotEmpty[F, T]): Boolean = ev.validate(field) | |
} | |
import Validations._ | |
case class Template(url: Option[String], | |
expectedHttpStatus: List[Int]) { | |
require(notEmpty(url), "url cannot be empty") | |
require(notEmpty(expectedHttpStatus), "expectedHttpStatus cannot be empty") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment