You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function which derives its input from a delegate function which is invoked based on the result of a given predicate. This is the object oriented version of a switch expression. Unlike a switch expression though, it can take any predicate of the switched type. The downside is we can't enforce the expression to be exhaustive.
This is a simple example of how it would be used
Function<String,String> f = newSwitch<>(
newCase<>(String::isEmpty, s -> "the String was empty"),
newCase<>(s -> s.length() == 1, s -> s + " contains a single character"),
newDefault<>(s -> s + " is " + s.length + " characters long"));
If no case matches an IllegalArgumentException is thrown.
The names Switch, Case and Default are not carved in stone. Other names like Case, When and Else might work too (e.g. Ruby style).
The text was updated successfully, but these errors were encountered:
A function which derives its input from a delegate function which is invoked based on the result of a given predicate. This is the object oriented version of a switch expression. Unlike a switch expression though, it can take any predicate of the switched type. The downside is we can't enforce the expression to be exhaustive.
This is a simple example of how it would be used
If no case matches an
IllegalArgumentException
is thrown.The names
Switch
,Case
andDefault
are not carved in stone. Other names likeCase
,When
andElse
might work too (e.g. Ruby style).The text was updated successfully, but these errors were encountered: