Last active
April 18, 2020 13:25
-
-
Save polyglotpiglet/ad0975f0a7de614f4a37b2dbb372684c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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