Coder Social home page Coder Social logo

Either constructors from `bool` about either HOT 5 CLOSED

asibahi avatar asibahi commented on August 20, 2024
Either constructors from `bool`

from either.

Comments (5)

cuviper avatar cuviper commented on August 20, 2024

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.

asibahi avatar asibahi commented on August 20, 2024

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.

cuviper avatar cuviper commented on August 20, 2024

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, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").

from either.

asibahi avatar asibahi commented on August 20, 2024

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.

cuviper avatar cuviper commented on August 20, 2024

Got it. Okay, I think we can leave it to your crate to offer a more opinionated stance. :)

from either.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.