Add additional Option methods#98
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
Optionequivalents of the followingSystem.Linq.Enumerablemethods: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.Concatover 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.AndOption.Union-->Option.OrOption.SelectMany-->Option.BindorOption.AndThenOption.SomeOrDefault-->Option.ConcatorOption.OrElseSomeOrDefaultis calledor_elsein Rust and C++23.SelectManyis variously calledand_then(Rust, C++23, Elm),bind(OCaml), orflat_map(Nim, Swift).Intersectis calledandin Rust, andUnionis calledorin Rust.