match_case 0.0.2 copy "match_case: ^0.0.2" to clipboard
match_case: ^0.0.2 copied to clipboard

outdated

A dart package for pattern matching.

A dart package for pattern matching. Inspired by match in Rust and when in Kotlin

Usage #

var x = 2;
var result = match(
  x,
  {
    1: () => "Its a one",
    () => x == 2 || x == 3: () => "Its a $x",
  },
  "Error!!", // (Optional) default value in case nothing is matched
);

// Output
$ "Its a 2"

match Definition #

U match<T, U>(
  T value, // Value that needs to be matched
  Map<T, U Function()> fns, // T -> Any primitive values or a function that returns true or false
  U defaultValue, // Optional value that is returned when nothing is matched
)
1
likes
0
points
31
downloads

Publisher

verified publishersabinbir.com.np

Weekly Downloads

A dart package for pattern matching.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on match_case