Skip to content
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

Non-null pipe ?|> #897

Open
edemaine opened this issue Dec 28, 2023 · 2 comments
Open

Non-null pipe ?|> #897

edemaine opened this issue Dec 28, 2023 · 2 comments
Labels
proposal Proposal or discussion about a significant language feature

Comments

@edemaine
Copy link
Collaborator

@STRd6 suggests the ability to short-circuit the rest of a pipe when the left-hand side is null:

x ?|> f
---
x != null ? f(x) : x
//or
x == null ? x : f(x)
@edemaine edemaine added the proposal Proposal or discussion about a significant language feature label Dec 28, 2023
@STRd6
Copy link
Contributor

STRd6 commented Mar 17, 2024

A possible refinement/expansion could be ?> and !> as pipe-if and pipe-unless.

foo := try line1() !> return
bar := try line2() !> return
...
vvv
let ref; try(){ref = line1()}catch(e){}; if(!ref) return ref; const foo = ref;

It passes the value to the pipe depending on the condition, then returns the value if not passed or the result of the of the pipe if it was passed.

It may need some finessing but that's the general idea.

Something else to consider could be a error/non-error pipe as well. It could pass if the value extends Error.

Some further questions:

  • Are non-null and falsey different enough to warrant different pipes?
  • Can we combine these easily? (pipe null or error, falsey or error, etc.)

👨‍🍳

@bbrk24
Copy link
Contributor

bbrk24 commented Mar 17, 2024

Are non-null and falsey different enough to warrant different pipes?

There are four distinct falsy values a number? may have, but only one of them is nullish. (The other three are 0, -0, and NaN.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal or discussion about a significant language feature
Projects
None yet
Development

No branches or pull requests

3 participants