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 Applicative syntax #884

Merged
merged 1 commit into from
Feb 24, 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
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package cats
package syntax

trait AllSyntax
extends ApplySyntax
extends ApplicativeSyntax
with ApplySyntax
with BifunctorSyntax
with BifoldableSyntax
with CartesianSyntax
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/scala/cats/syntax/applicative.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cats
package syntax

trait ApplicativeSyntax {
implicit def applicativeIdSyntax[A](a: A): ApplicativeIdOps[A] = new ApplicativeIdOps[A](a)
implicit def applicativeEvalSyntax[A](a: Eval[A]): ApplicativeEvalOps[A] = new ApplicativeEvalOps[A](a)
}

final class ApplicativeIdOps[A](val a: A) extends AnyVal {
def pure[F[_]](implicit F: Applicative[F]): F[A] = F.pure(a)
}

final class ApplicativeEvalOps[A](val a: Eval[A]) extends AnyVal {
def pureEval[F[_]](implicit F: Applicative[F]): F[A] = F.pureEval(a)
}
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 @@ -2,6 +2,7 @@ package cats

package object syntax {
object all extends AllSyntax
object applicative extends ApplicativeSyntax
object apply extends ApplySyntax
object bifunctor extends BifunctorSyntax
object bifoldable extends BifoldableSyntax
Expand Down
8 changes: 8 additions & 0 deletions tests/src/test/scala/cats/tests/SyntaxTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,12 @@ class SyntaxTests extends AllInstances with AllSyntax {
val g2 = mock[B => D]
val d0 = fab.bifoldMap(f2, g2)
}

def testApplicative[F[_]: Applicative, A]: Unit = {
val a = mock[A]
val fa = a.pure[F]

val la = mock[Eval[A]]
val lfa = la.pureEval[F]
}
}