zajrik / option_result

A lightweight Dart library for Rust-like Option/Result types and associated pattern matching
https://pub.dev/packages/option_result
MIT License
10 stars 1 forks source link

Remove value getters, update docs and tests #4

Closed manuel-plavsic closed 7 months ago

manuel-plavsic commented 10 months ago

This pull request removes all additional getters and retains only the one associated with the field name. It is advisable to use uniform getters for consistency. If additional getters are desired, extensions can be made on a project basis.

I would stick to just v for Option and Ok, and e for Err because they are concise and because this makes using pattern matching more straightforward. E.g. the following snippet

print(switch (foo) {
  Some(value: var bar) => 'Some value: $bar',
  None() => 'No value!'
});

is more verbose than the next one

print(switch (foo) {
  Some(v: var bar) => 'Some value: $bar',
  None() => 'No value!'
});

I also believe, for example, that having one field with four getters for 'Err' is a bit excessive.

What is your opinion on this?

Note: dart formatted the source code and replaced tabs with empty spaces.

manuel-plavsic commented 10 months ago

I find pattern matching much easier to read when each pattern has its own dedicated line. That's why I added some commas.