James Hales


Software Engineer at Commonwealth Bank

I’m a software engineer in Omnia at the Commonwealth Bank of Australia. I previously completed a Ph.D. in Computer Science and a Bachelor of Computer and Mathematical Sciences (First Class Honours) at the University of Western Australia.

YOW! Lambda Jam 2016 Brisbane

Design your own Optics to Improve Composability and Testability


Optics, such as lenses and prisms, are accessors / mutators for data structures, that can be elegantly composed to access / mutate positions deep within nested data structures. For some of our real world use cases we were unable to take full advantage of the composability of optics. In one case we could compose a sequence of optics to access a desired position in a data structure, but the same optic couldn’t mutate the position in the way we desired. We also found that composing a sequence of optics that each optionally access a position would obscure which optic in the sequence failed – which we needed to know in practice for error-reporting purposes. Consequently we were forced to “manually” compose optics for the desired behaviour, and the result was far less elegant or easily testable than composing sequences of optics. That is, until we wised up and designed our own composable, testable, optics that behaved the way we wanted.

This talk is a case study of how we improved the composability and testability of our components by designing optics with the behaviour we desired. We’ll walk through a simplified version of the problem we were trying to solve, the limitations we faced with vanilla optics, and how we solved the problem more elegantly by designing our own optics. The optics will be open sourced as a Scala library that complements the monocle library of optics by Julien Truffaut, et al.