Skip to content

Instantly share code, notes, and snippets.

@harmeetsingh0013
Created July 7, 2018 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harmeetsingh0013/adfc168092f55523e21dd6b7190dbfc4 to your computer and use it in GitHub Desktop.
Save harmeetsingh0013/adfc168092f55523e21dd6b7190dbfc4 to your computer and use it in GitHub Desktop.
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