-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional Option
methods
#98
base: master
Are you sure you want to change the base?
Conversation
Add `Option` equivalents of the following `System.Linq.Enumerable` methods: * `Intersect`: a kind of eager Boolean "and" over 2 options. Returns the second option unless the first is None. * `Union`: a kind of eager Boolean "or" over 2 options. Returns the first option unless it is None. * `SelectMany`: a chainable version of Select akin to `Enumerable.SelectMany`. The supplied function returns an option rather than a bare type, and the result type is the function's result type. * `SomeOrDefault`: a kind of `Enumerable.Concat` over an option and an option-generating thunk. If the option is None, call the thunk to generate a default option. All names of these new methods are open to revision. These are less common methods and their names vary in other programming languages. Alternatives might be: * Option.Intersect --> Option.And * Option.Union --> Option.Or * Option.SelectMany --> Option.Bind or Option.AndThen * Option.SomeOrDefault --> Option.Concat or Option.OrElse SomeOrDefault is called `or_else` in Rust and C++23. SelectMany is variously called `and_then` (Rust, C++23, Elm), `bind` (OCaml), or ``flat_map` (Nim, Swift).
@rabeckett Feel free to suggest alternative names. One option (ha ha) is to stick very closely to
Names that might be less aligned with |
Very nice. In terms of naming, I find the rust naming convention to be fairly sensible.
A few other useful variants in rust, that are similar to |
Names of new Option methods now match those used by Rust, i.e. Option.Or, Option.OrElse, Option.And, Option.AndThen.
Sounds good, I've updated the naming scheme. |
Add
Option
equivalents of the followingSystem.Linq.Enumerable
methods:Intersect
: a kind of eager Boolean "and" over 2 options. Returns the second option unless the first is None.Union
: a kind of eager Boolean "or" over 2 options. Returns the first option unless it is None.SelectMany
: a chainable version of Select akin toEnumerable.SelectMany
. The supplied function returns an option rather than a bare type, and the result type is the function's result type.SomeOrDefault
: a kind ofEnumerable.Concat
over an option and an option-generating thunk. If the option is None, call the thunk to generate a default option.All names of these new methods are open to revision. These are less common methods and their names vary in other programming languages. Alternatives might be:
Option.Intersect
-->Option.And
Option.Union
-->Option.Or
Option.SelectMany
-->Option.Bind
orOption.AndThen
Option.SomeOrDefault
-->Option.Concat
orOption.OrElse
SomeOrDefault
is calledor_else
in Rust and C++23.SelectMany
is variously calledand_then
(Rust, C++23, Elm),bind
(OCaml), orflat_map
(Nim, Swift).Intersect
is calledand
in Rust, andUnion
is calledor
in Rust.