Last updated:
0 purchases
match case
A dart package for pattern matching. Inspired by match in Rust and when in Kotlin
Usage #
var x = 11;
var result = match(
x,
{
eq(1): () => "Its a one",
eq(2): () => "Its a $x",
gt(2) & lt(10): () => "Greater than 2",
(digit) => digit == 11: () => "Its an eleven",
},
other: val("Error!!"),
);
expect(result, "Its an eleven");
copied to clipboard
match Definition #
U match<T, U>(
T value, // Value that needs to be matched
Map<bool Function(T), U Function()> fns, {
required U Function() other, // a method to return the default value
})
copied to clipboard
List of helper matcher function #
1. eq(T value)
2. neq(T value)
3. gt(num number)
4. lt(num number)
5. gte(num number)
6. lte(num number)
7. range(num from, num to)
copied to clipboard
List of helper function for other param #
1. val(T value) // Function that returns the passed value
2. nil<T>() // Function that returns null
copied to clipboard
List of operators #
1. &
2. |
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.