Comments (5)
You removed Option
from the title, but that was briefly discussed in #15. The symmetry mentioned there is stated in the documentation for Either
:
The Either type is symmetric and treats its variants the same way, without preference. (For representing success or error, use the regular Result enum instead.)
I think this applies to bool
as well -- there's no inherent mapping that says true
should be Left
or Right
.
from either.
I did remove Option
since I did see that issue. The reasoning there made sense and the function I wrote doesn't make sense when applied to Options.
My rationale for treating Left
as truthy is basically just that the visual order: if cond { Left(left) } else { Right(right) }
orders them the same as cond.either(left, right)
.
I have been informed that Haskell (for example) generally treats Right as truthy as well.
from either.
I have been informed that Haskell (for example) generally treats Right as truthy as well.
"as well"? Doesn't that contradict the Left
-truthy position you're advocating?
The derived Ord
and PartialOrd
also support that direction, where false < true
and Left(_) < Right(_)
.
But I think truthiness is still a kind of preference that we're trying to avoid. Haskell is more opinionated:
The
Either
type is sometimes used to represent a value which is either correct or an error; by convention, theLeft
constructor is used to hold an error value and theRight
constructor is used to hold a correct value (mnemonic: "right" also means "correct").
from either.
Meant "as well" as in adding to what you said.
I understand why you might not want to add this to this crate. I think I will try creating a crate of my own implementing them, as it would be also a learning experience for me. Thanks for the comments.
from either.
Got it. Okay, I think we can leave it to your crate to offer a more opinionated stance. :)
from either.
Related Issues (20)
- Use Github Actions for CI
- Publicly expose the `either!` macro? HOT 5
- Trait to add `right_or(Left)` to `Option<Right>`. HOT 2
- Provide "into-common-type" function HOT 1
- Missing rfold and nth_back specializations on DoubleEndedIterator impl
- Bring `std::error::Error` implementation up to latest version HOT 2
- Allow pin projection HOT 13
- Change `impl Future for Either` to `Output = Either` HOT 14
- Implement `bimap` which combines `left_map` and `right_map` HOT 2
- Add `flatten`, `flatten_right` and `flatten_left` methods HOT 2
- serde derive feature HOT 1
- Generalize inner types for better Serde integration HOT 3
- Add more Iterator helper methods
- FEATURE REQUEST: some (attribute?) macro to implement our trait for Either easily HOT 3
- New crates.io owner? HOT 4
- Feat: Conditionally applied methods HOT 9
- A way to update value using the previous one HOT 2
- Enable serde on playground HOT 3
- Add a `FromEither` trait HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from either.