Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
That does show the power of pattern matching. You can capture a lot of permutations in a relatively small amount of code this way.
I'm partial to having descriptive names for operations, so I like how the current isLegalMove reads like English: areCardsDifferentColor && areRanksInDescendingOrder reads exactly like the game rules are stated.
That can remain the same and we can use this technique to reimplement areCardsDifferentColor:
Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
Yeah, the way you broke down the implementation into helper functions at a lower level of abstraction–the step method–is probably more maintainable overall!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I had a little fun implementing the function directly partitioning the inputs by case:
That does show the power of pattern matching. You can capture a lot of permutations in a relatively small amount of code this way.
I'm partial to having descriptive names for operations, so I like how the current
isLegalMove
reads like English:areCardsDifferentColor && areRanksInDescendingOrder
reads exactly like the game rules are stated.That can remain the same and we can use this technique to reimplement
areCardsDifferentColor
:It's definitely fun to think about the best way to express things.
Yeah, the way you broke down the implementation into helper functions at a lower level of abstraction–the step method–is probably more maintainable overall!