Skip to content

Instantly share code, notes, and snippets.

@polyglotpiglet
Last active April 18, 2020 13:25
Show Gist options
  • Save polyglotpiglet/ad0975f0a7de614f4a37b2dbb372684c to your computer and use it in GitHub Desktop.
Save polyglotpiglet/ad0975f0a7de614f4a37b2dbb372684c to your computer and use it in GitHub Desktop.
object Main extends App {
import cats._
import cats.implicits._
def power[F[_]](f: F[Int])(implicit func: Functor[F]): F[Int] = {
f.map(x => x*x)
}
println(power(List(1,2,3)))
println(power(Option(2)))
// alternative syntax
def power2[F[_] : Functor](in: F[Int]): F[Int] = {
in.map(i => i * i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment