Skip to content

Instantly share code, notes, and snippets.

@globulon
Created May 22, 2012 09:13
Show Gist options
  • Select an option

  • Save globulon/2767761 to your computer and use it in GitHub Desktop.

Select an option

Save globulon/2767761 to your computer and use it in GitHub Desktop.
Invalid definition
trait SequenceValidation[A, B] {
self =>
def apply(seq: Seq[A]): DomainValidation[Seq[B]]
def map[C](f: B => C) = new SequenceValidation[A, C] {
def apply(seq: Seq[A]): DomainValidation[Seq[C]] =
self.apply(seq) map { validSequence => validSequence map f }
}
def flatMap[C](f: B => SequenceValidation[A, C]) = new SequenceValidation[A, C] {
def apply(seq: Seq[A]): DomainValidation[Seq[C]] = {
val result: DomainValidation[Seq[DomainValidation[Seq[C]]]] = self.apply(seq) map { validSequence =>
validSequence map { item =>
f(item)(seq)
}
}
result.flatMap { s =>
s.sequence map { sp => sp.flatten}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment