Skip to content

Commit

Permalink
Add applicative syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
notxcain committed Feb 17, 2016
1 parent 6fe593d commit f308b08
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
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]
}
}

0 comments on commit f308b08

Please sign in to comment.