Created
July 7, 2018 10:02
-
-
Save harmeetsingh0013/adfc168092f55523e21dd6b7190dbfc4 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 IdExample1 extends App { | |
def sumSquare[F[_]: Monad](a: F[Int], b: F[Int]): F[Int] = { | |
a.flatMap(x => b.map(y => x*x + y*y)) | |
} | |
import cats.instances.list._ | |
import cats.instances.option._ | |
val result1 = sumSquare(Option(2), Option(5)) | |
println(result1) | |
val result2 = sumSquare(List(1, 2, 3), List(4, 5, 6)) | |
println(result2) | |
// val result3 = sumSquare(2, 4) //Getting error | |
// println(result3) | |
val result4 = sumSquare(2: Id[Int], 4: Id[Int]) //Getting error | |
println(result4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment