scala reducer simulation