In this talk we describe an underappreciated tool, Church encoding, that allows us to combine the best parts of FP and OO. By Church encoding our program we can retain the simple semantics that characterises FP code, while achieving performance that may seem out of reach in a pure FP system.
Late last year Maana, a Seattle based enterprise knowledge platform startup, contracted us to write a time series analysis engine. They commonly dealt with multi-TB data, but needed to achieve interactive speed. We recognised that providing a streaming API, similar to Monix, Akka Streams, or Reactive Extensions, would make the software accessible to data scientists already used to Spark, but there were issues about semantics and performance. Classic FP pull-based systems are simple to use but perform poorly, while OO push-based systems are fast but tricky to reason about. By employing Church encoding, also known as refunctionalisation, we were able to get the best of both worlds.