Skip to content

Instantly share code, notes, and snippets.

@afsalthaj
Last active April 19, 2018 01:20
Show Gist options
  • Save afsalthaj/59e5747b55d725815a70202904d88538 to your computer and use it in GitHub Desktop.
Save afsalthaj/59e5747b55d725815a70202904d88538 to your computer and use it in GitHub Desktop.
@ //This is ammonite configured for shapeless
@ object NewNumber extends Tagger[Int]
defined object NewNumber
@ type NewNumber = NewNumber.Type
defined type NewNumber
@ case class World(name: Name, exchangId: ExchangeId, newNumber: NewNumber)
defined class World
@ implicit val newNumberValidation: Validation[NewNumber] =
a =>
if (Tag.unwrap(a) > 10)
(ValidationError.InvalidValue("NewNumber is greater than 10"): ValidationError).failureNel[NewNumber]
else
a.successNel[ValidationError]
newNumberValidation: Validation[Int] = ammonite.$sess.cmd50$$$Lambda$2743/796603018@4e1984de
@ implicitly[Validation[World]].validate(World(Name("name"), ExchangeId("id"), 1))
res51: ValidationNel[ValidationError, World] = Success(World("name", "id", 1))
@ implicitly[Validation[World]].validate(World(Name("name"), ExchangeId("id"), 11))
res52: ValidationNel[ValidationError, World] = Failure(NonEmpty[InvalidValue(NewNumber is greater than 10)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment