Skip to content

feat: Add the pipeline operator |> for chained method calls.#1061

Closed
yonas wants to merge 1 commit intorhaiscript:mainfrom
yonasBSD:feat/pipeline-operator
Closed

feat: Add the pipeline operator |> for chained method calls.#1061
yonas wants to merge 1 commit intorhaiscript:mainfrom
yonasBSD:feat/pipeline-operator

Conversation

@yonas
Copy link
Copy Markdown

@yonas yonas commented Jan 3, 2026

Fixes #1062

@yonas yonas force-pushed the feat/pipeline-operator branch 2 times, most recently from 0d47614 to 2f5c842 Compare January 3, 2026 22:43
@yonas yonas force-pushed the feat/pipeline-operator branch from 2f5c842 to 3dd6cc5 Compare January 3, 2026 22:47
}

// Range iterator with step
#[derive(Clone, Hash, Eq, PartialEq)]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the derive attributes?

Comment thread src/parser.rs
#[cfg(not(feature = "no_module"))]
let (_index, name, namespace, _hash) = x;
#[cfg(feature = "no_module")]
let (index, name) = x;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI seems to complain about index being unused here...

Comment thread src/parser.rs

Expr::FnCall(fn_call.into(), pos)
}
_ => op_base.into_fn_call_expr(pos),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need parsing errors if the stuff following the operator is not a proper function call, instead of allowing it to go through.

Comment thread src/tokenizer.rs

Precedence::new(match self {
Or | XOr | Pipe => 30,
Or | XOr | Pipe | PipeArrow => 30,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a lower precedence for |>?

Comment thread src/tokenizer.rs
}
('|', '>') => {
stream.eat_next_and_advance(pos);
return (Token::Reserved(Box::new("|>".into())), start_pos);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to be careful here... some users may depend on the fact that |> is a reserved symbol and define it as a custom operator. This may break code, but I see that you're checking this after checking for custom operators...

Comment thread src/parser.rs
name: self.get_interned_string(&op),
hashes: FnCallHashes::from_native_only(hash),
args: IntoIterator::into_iter([root, rhs]).collect(),
args: IntoIterator::into_iter([root.clone(), rhs.clone()]).collect(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is it necessary to clone the arguments?

@schungx
Copy link
Copy Markdown
Collaborator

schungx commented Mar 22, 2026

I'm going to close this for the time being as I'm not convinced that adding a new operator would add much. Feel free to reopen.

@schungx schungx closed this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ feature request ] Add the pipeline operator |> for chained method calls

2 participants