functional experiments in scala about state transitions