Created
May 22, 2012 09:43
-
-
Save globulon/2767900 to your computer and use it in GitHub Desktop.
Possible Solution
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
| trait SequenceValidation[B] { | |
| self => | |
| def apply[A](seq: Seq[A]): DomainValidation[Seq[B]] | |
| def map[C](f: B => C) = new SequenceValidation[C] { | |
| def apply[A](seq: Seq[A]): DomainValidation[Seq[C]] = | |
| self.apply(seq) map { validSequence => validSequence map f } | |
| } | |
| def flatMap[C](f: B => SequenceValidation[C]) = new SequenceValidation[C] { | |
| def apply[A](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