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 flap function to Apply #2588

Merged
merged 5 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions core/src/main/scala/cats/syntax/all.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ trait AllSyntax
with EqSyntax
with FlatMapSyntax
with FoldableSyntax
with Function1Syntax
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

due to binary compatibility restrictions, you can't add it to this trait either. However, you can add it to AllSyntaxBinCompat3 which is a new trait that hasn't been released yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. 👍

with FunctorSyntax
with GroupSyntax
with HashSyntax
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/scala/cats/syntax/function1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cats
package syntax

trait Function1Syntax {

implicit def catsSyntaxFunction1[F[_]: Functor, A, B](fab: F[Function1[A, B]]): Function1Ops[F, A, B] =
new Function1Ops[F, A, B](fab)

final class Function1Ops[F[_]: Functor, A, B](fab: F[Function1[A, B]]) {
/**
* Given a function in the Functor context and a plain value, supplies the
* value to the function.
*
* Example:
* {{{
* scala> import cats.implicits._
*
* scala> val someF: Option[Int => Long] = Some(_.toLong + 1L)
* scala> val noneF: Option[Int => Long] = None
* scala> val anInt: Int = 3
*
* scala> someF.mapApply(anInt)
* res0: Option[Long] = Some(4)
*
* scala> noneF.mapApply(anInt)
* res1: Option[Long] = None
*
* }}}
*/
def mapApply(a: A): F[B] = Functor[F].map(fab)(_(a))
}
}