Permalink
Browse files

Compose function implementation

  • Loading branch information...
1 parent 1ab74b8 commit 406a7ae487f33ac0f3b2baa0c1470d9f61897fea @rboles committed Feb 27, 2014
Showing with 10 additions and 2 deletions.
  1. +10 −2 exercises/src/main/scala/fpinscala/gettingstarted/GettingStarted.scala
@@ -230,6 +230,14 @@ object PolymorphicFunctions {
// Exercise 6: Implement `compose`
- def compose[A,B,C](f: B => C, g: A => B): A => C =
- ???
+ def compose[A,B,C](f: B => C, g: A => B): A => C = {
+ def h(a: A): C = f(g(a))
+ h
+ }
+
+ // With a function literal
+ def composeCompact[A,B,C](f: B => C, g: A => B): A => C = {
+ (a: A) => f(g(a))
+ }
+
}

0 comments on commit 406a7ae

Please sign in to comment.