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 SValidation[A] { | |
| def apply(seq: A): DomainValidation[A] | |
| def map[B](f: A => B) = new SValidation[B] { | |
| def apply(seq: B): DomainValidation[B] = null | |
| // self.apply(seq) map { validSequence => validSequence map f } | |
| } | |
| def flatMap[B](f: A => SValidation[B]) = new SValidation[B] { | |
| def apply(seq: B): DomainValidation[B] = null |
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 SValidation[A] { | |
| self => | |
| def apply(seq: Seq[A]): DomainValidation[Seq[A]] | |
| def map[B](f: A => B) = new SValidation[B] { | |
| def apply(seq: Seq[B]): DomainValidation[Seq[B]] = null | |
| // self.apply(seq) map { validSequence => validSequence map f } | |
| } | |
| def flatMap[B](f: A => SValidation[B]) = new SValidation[B] { | |
| def apply(seq: Seq[B]): DomainValidation[Seq[B]] = null |
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 SValidation[A] { | |
| self => | |
| def apply(seq: Seq[A]): DomainValidation[Seq[A]] | |
| def map[B](f: A => B) = new SValidation[B] { | |
| def apply(seq: Seq[B]): DomainValidation[Seq[B]] = null | |
| // self.apply(seq) map { validSequence => validSequence map f } | |
| } | |
| } |
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[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] { |
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
| def drop1Keep1[E]: IterV[E, Option[E]] = for { | |
| _: Unit <- drop[E](1) | |
| h: Option[E] <- head[E] | |
| } yield h | |
| def repeat[E, A](iter: IterV[E, A], n: Int): IterV[E, List[A]] = { | |
| type P[X] = IterV[E, X] | |
| implicit val appl = iterateesToApplicative[E]() | |
| replicateM[A, P, List](iter, n) |
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
| def replicateM[T, M[_]: Applicative, C[_]: MonoidC : Traverse](a: M[T], n: Int): M[C[T]] = { | |
| implicitly[Traverse[C]].sequence(a.replicate(n)) | |
| } |
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
| implicit def toReplicable[T](value: T) = Replicable(value) | |
| implicit def toReplicableM[T, M[_]](m: M[T]) = ReplicableM(m) |
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 SemiGroup[T] { | |
| def add(x: T, y: T): T | |
| } | |
| trait Monoid[T] extends SemiGroup[T] { | |
| def unit: T | |
| } | |
| trait MonoidC[L[X]] { | |
| def add[T](k: L[T], l: L[T]): L[T] |
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
| package com.promindis.patterns | |
| final case class Replicable[T](value: T) { | |
| def replicate[L[_]](n: Int)(implicit m: MonoidC[L]): L[T] = { | |
| def replicateIter(acc: L[T], rest: Int): L[T] = { | |
| if (rest == 0) acc | |
| else replicateIter(m.add(acc, m(value)), rest - 1) | |
| } | |
| replicateIter(m.unit, n) | |
| } |
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
| def drop1Keep1[E]: IterV[E, Option[E]] = for { | |
| _: Unit <- drop[E](1) | |
| h: Option[E] <- head[E] | |
| } yield h |