this post was submitted on 06 Sep 2025
109 points (95.0% liked)

Programming

22764 readers
29 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] Asetru@feddit.org 17 points 2 weeks ago (2 children)

The or() combinator means exactly one succeeds.

Using "or" to define a function that does "xor"... Did that guy never hear about formal logic? That's, like, first or second semester stuff...

Here's the thing: I don't have a CS degree.

sigh

[–] theherk@lemmy.world 15 points 2 weeks ago

Could have used oneOf or exactlyOne, but or is definitely a bad choice.

[–] Glitchvid@lemmy.world 1 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

It's an understandable interpretation for the lexical use of or which can imply exclusive disjunction.

In Rust the result type has the method .or() which returns either Ok(A) or Ok(B) (but not both), and I don't see clambering to change it to xor, because the exclusive nature is implicit both linguistically and in the type state.

[–] Asetru@feddit.org 1 points 1 week ago* (last edited 1 week ago) (1 children)

The result type in rust does not return a true/false but a type. More importantly though, it doesn't return err if both values are set but simply returns the first value:

So... It's not only not mapping your input to truth values, it also behaves more like I'd expect an "or" to behave, which is not "xor" or, if there's more than two inputs, "exactly one", but succeeding if any input is set.

[–] Glitchvid@lemmy.world 1 points 1 week ago* (last edited 1 week ago) (1 children)

...Which is basically how the OP's or function also works, it takes several Option<T>s and returns the first valid one (and only that one), it doesn't operate on boolean logic types — it's a valid lexical use of or.

[–] Asetru@feddit.org 1 points 1 week ago

Absolutely not.

Mutually exclusive options

Another classic. Pick one output format: JSON, YAML, or XML. But definitely not two.

Emphasis mine.

It takes the input and fails if there is more than one valid one, which decidedly isn't what's an "or" in comp sci.