On the series about GoF patterns in Scala, last week I proposed an implementation of Command pattern. I wasn’t however fully satisfied with the result because of not being functional but Object Oriented, so this week I am proposing a different implementation. This one is fully functional, based on typeclasses.
Before going to the implementation -which is pretty obvious- I’d like to point out a couple things.
- Note that we are choosing the Receiver that will execute the instructions importing it as an instance. That is cool!
- As a negative note, this implementation does not allow saving a list of commands and executing all of them like in the OO version. That is a serious limitation of this proposal, as one important characteristic of the Command pattern is being able to log the commands.