Created
October 8, 2019 19:11
-
-
Save psilospore/386e8b01f8c1af1a71911c0b535d30ed to your computer and use it in GitHub Desktop.
learninCats-Parallel
This file contains 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
object ParEitherNonEmpty { | |
import cats.data.NonEmptyList.catsDataSemigroupForNonEmptyList | |
import cats.data.{NonEmptyList, Validated} | |
new Parallel[Either[NonEmptyList[_], ?]] { | |
override type F[v] = Validated[NonEmptyList[_], v] | |
override def applicative: Applicative[Validated[NonEmptyList[_], *]] = { | |
Validated.catsDataApplicativeErrorForValidated[NonEmptyList[_]](catsDataSemigroupForNonEmptyList) | |
} | |
override def monad: Monad[Either[NonEmptyList[_], ?]] = cats.instances.either.catsStdInstancesForEither | |
override def sequential: ~>[F, Either[NonEmptyList[_], ?]] = new FunctionK[F, Either[NonEmptyList[_], ?]]{ | |
override def apply[A](fa: Validated[NonEmptyList[_], A]): Either[NonEmptyList[_], A] = fa match { | |
case Validated.Valid(a) => Right(a) | |
case Validated.Invalid(e) => Left(e) | |
} | |
} | |
override def parallel: ~>[Either[NonEmptyList[_], ?], F] = new ~>[Either[NonEmptyList[_], ?], F] { | |
override def apply[A](fa: Either[NonEmptyList[_], A]): F[A] = fa match { | |
case Right(value) => Validated.valid(value) | |
case Left(err) => Validated.invalid(err) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment