An optional scala implementation for the motivation