Closed johnmcclean closed 6 years ago
match could well be a method on the Function type F[0-8]. That way it could be used with Tuples from most major libraries (e.g. jool via map( ) or JavaSlang via transform( )
Upgraded pattern matching in Cyclops X
Moving to cyclops-react 2.x is a good opportunity to simplify pattern matching based on what works (and remove what doesn't).
What works well
The 'catamorphism' type visit methods are simple, easy to use and are used extensively internally inside the library. They are also a large part of the value prop of cyclops-sum-types.
What works less well
The nested function match methods are harder to use.
We can match on the structure of most objects types by converting them to a Tuple or Either / Xor type. jOOλ Tuples have a 'map' method that could be used as the basis of a simpler pattern matching.
e.g.
We can can pass a BiFunction that accepts the component values and returns a result, this function should be composed with another function that accepts two Predicates and returns the result if those predicates match.
e.g.
with cyclops Predicates this could be rewritten as
If match looks something like this
Then we can define cases recursively inside the miss function
We can further simplify this by defining a MTuple set of classes with a single method "match"
That way we can do pattern matching which just relies on plain old Java 8 Predicates with no internal infrastructure to maintain.