--
You received this message because you are subscribed to the Google Groups "scala-functional" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-function...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class ex03 {
def partial1[A,B,C](a:A, f:(A,B) => C): B => C = f(a,_)
}
class ex03Test extends UnitSpec {
behavior of "partial1"
it should "return 6" in {
val e = new ex03
val multiplyByTwo = e.partial1(2, (a:Int, b:Int) => a * b)
multiplyByTwo(3) mustBe 6
}
}
Hi Harit,It might bend your mind a bit if you are just starting out with FP, but you'll get a hang of it.Let's start with the function definition:
def partial1[A,B,C](a:A, f:(A,B) => C):B=>C
We need to return a function that takes a B and returns a C. Let's type it out
def partial1[A,B,C](a:A, f:(A,B) => C):B=>C = {
// return a function that takes a B and returns a C(b: B) => /* Somehow get a value of type C here */}How can we get a value of type C? To help us out, we can use the function f that takes (A,B) and returns a C.def partial1[A,B,C](a:A, f:(A,B) => C):B=>C = {// return a function that takes a B and returns a C(b: B) => f(a, b)}This can be shortened todef partial1[A,B,C](a:A, f:(A,B) => C):B=>C = f(a, _)But if you find the last definition hard to comprehend, stick to the previous one till you get more comfortable with Scala.ThanksParam
--You received this message because you are subscribed to a topic in the Google Groups "scala-functional" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-functional/tfLo14qU72E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-function...@googlegroups.com.