Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ScalaDoc examples for Coproduct syntax #784

Merged
merged 1 commit into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions core/src/main/scala/cats/syntax/coproduct.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,37 @@ trait CoproductSyntax {
implicit def coproductSyntax[F[_], A](a: F[A]): CoproductOps[F, A] = new CoproductOps(a)
}

final class CoproductOps[F[_], A](val a: F[A]) extends AnyVal {
def leftc[G[_]]: Coproduct[F, G, A] = Coproduct.leftc(a)
def rightc[G[_]]: Coproduct[G, F, A] = Coproduct.rightc(a)
final class CoproductOps[F[_], A](val fa: F[A]) extends AnyVal {

/**
* Lift an `F[A]` into a `Coproduct[F, G, A]` for any type constructor `G[_]`.
*
* @see [[rightc]] to swap the order of `F` and `G` in the result type.
*
* Example:
* {{{
* scala> import cats.data.Coproduct
* scala> import cats.Eval
* scala> import cats.syntax.coproduct._
* scala> List(1, 2, 3).leftc[Eval]
* res0: Coproduct[List, Eval, Int] = Coproduct(Left(List(1, 2, 3)))
* }}}
*/
def leftc[G[_]]: Coproduct[F, G, A] = Coproduct.leftc(fa)

/**
* Lift an `F[A]` into a `Coproduct[G, F, A]` for any type constructor `G[_]`.
*
* @see [[leftc]] to swap the order of `F` and `G` in the result type.
*
* Example:
* {{{
* scala> import cats.data.Coproduct
* scala> import cats.Eval
* scala> import cats.syntax.coproduct._
* scala> List(1, 2, 3).rightc[Eval]
* res0: Coproduct[Eval, List, Int] = Coproduct(Right(List(1, 2, 3)))
* }}}
*/
def rightc[G[_]]: Coproduct[G, F, A] = Coproduct.rightc(fa)
}
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package object syntax {
object monoidal extends MonoidalSyntax
object bifunctor extends BifunctorSyntax
object coflatMap extends CoflatMapSyntax
object coproduct extends CoproductSyntax
object comonad extends ComonadSyntax
object compose extends ComposeSyntax
object contravariant extends ContravariantSyntax
Expand Down