Skip to content

Instantly share code, notes, and snippets.

@rm--
Forked from harmeetsingh0013/IdExample1.scala
Last active October 26, 2018 10:44
Show Gist options
  • Save rm--/d285ac3b69372d18aa60ed7f4bf60b2a to your computer and use it in GitHub Desktop.
Save rm--/d285ac3b69372d18aa60ed7f4bf60b2a to your computer and use it in GitHub Desktop.
scratch file
import cats._
import cats.syntax.flatMap._
import cats.syntax.functor._
import cats.syntax.applicative._
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