Would you mind writing this in scala?