Partial functions, currying and composition
I've been working through Functional Programming in Scala by Chiusano and Bjarnason lately, and it's been a really awesome book. This morning I worked on a few exercises on partial function application, currying and composition that I think demonstrate how powerful Scala can be. I just wanted to paste my solutions here and their translations to Python (3.6), because it's really cool and I'd love feedback on them.
Partial Function Application
First is partial function application. In Scala my solution to this exercise looks as follows.
object HOF_Testing { def partial[A, B, C](a: A, f: (A, B) => C): B => C = (b: B) => f(a, b) def main(args: Array[String]): Unit = { // Test this partial function method on an anonymous function val x = 5 val y = 6 println("** Partial function application: " + partial[Int, Int, Int](x, (u, v) => u + v)(y)) } } // ** Partial function application: 11 In Python we can achieve the same result…
Partial Function Application
First is partial function application. In Scala my solution to this exercise looks as follows.
object HOF_Testing { def partial[A, B, C](a: A, f: (A, B) => C): B => C = (b: B) => f(a, b) def main(args: Array[String]): Unit = { // Test this partial function method on an anonymous function val x = 5 val y = 6 println("** Partial function application: " + partial[Int, Int, Int](x, (u, v) => u + v)(y)) } } // ** Partial function application: 11 In Python we can achieve the same result…