Jason Liberman

Jason Liberman
Bridgewater Associates

After studying abstract math and philosophy in school, Jason worked at a bank for two years before deciding to teach himself to code. Scala was actually the first programming language he ever learned when he became an Investment Engineer at Bridgewater two years ago. As an Investment Engineer, he develops and maintains portfolio construction logic primarily using functional Scala. He is incredibly passionate about reading books, functional programming, creating a great community for his engineering team, lifelong learning, playing instruments, and philosophy.


I will discuss a few of the limitations our engineers have found with Scala’s built-in immutable Map collection to represent key-value pairs. I will present a simple immutable collection (PMaps) that we built to overcome some of the problems we found and enable powerful, principled, and clean code.



Have you ever tried adding a default to a Scala Map and lamented that downstream references have no idea that the default exists? Or unknowingly clobbered values in your Map by adding a value whose key was already present? Or do you ever want to combine two or more Maps with some operation (e.g. add, subtract, multiply)?

While Scala Maps are powerful and fast, my fellow engineers and I kept running into some of their limitations, so I set out to improve them. My solution was a relatively lightweight Map collection that wraps a Scala Map, with the goals of protecting my fellow engineers from some of the unsafe properties of Maps while also enabling rich and expressive functionality on collections of key-value pairs. For example, PMaps enable:

  • Adding a default that is represented in the type of the collection
  • Convenient arithmetic operations on the collection level – e.g. adding or subtracting the values of two collections
  • Explicitly handle errors when you add overlapping keys
  • ‘Join’ functionality that allows us to write expressive and readable business logic combining multiple collections


In the talk, I hope to:

  • Motivate some of the shortcomings with Scala’s built-in immutable Map collection and our decision to build our own simple Map collection.
  • Describe the functional programming and Scala patterns and principles I relied on, and the tradeoffs I came across in building PMaps.
  • Show off some of the functionality of PMaps and how they enable rich and clean logic.


This talk is meant to be accessible for all levels of Scala experience. Type classes and F-Bounded Polymorphism might be mentioned briefly, but most of the talk will be understandable for beginners and hopefully relevant even for experienced Scala users.