hauleth

hauleth

Simple and clean library that is inspired by discussion in Elixir’s issue tracker and uses operator suggested by @josevalim (however it may change, other operator that I was considering was &_)

Short example of how this works:

# Old pipes work as it have been before
iex> 5 |> Integer.to_string()
"5"
iex> 5 |> Integer.to_string(2)
"101"

# You can use `...` to mark the point where the expression should be inserted
iex> 5 |> Integer.to_string(10, ...)
"20"

For now it works only with function calls, so unfortunately no support for stuff like {:ok, ...}, [..., 2], or %{a: ...}. It also do not work with things like 1 |> struct(URI, port: ...) as the ... operator must be top level.

I wanted to create another one (the other one is @Qqwy’s CapturePipe) to test out using another operator, that would be IMHO less confusing than &1 in CapturePipe.

Showing Posts 1 to 10

bluejay

bluejay

Nice work. It might be obvious to others, but you may wish to add in the docs that you need to use Magritte not import Magritte.

hauleth

hauleth OP

Yes, I am still writing the docs to be clearer on the usage.

Qqwy

Qqwy

TypeCheck Core Team

I’m very eager to see how this will develop. CapturePipe has two disadvantages, both related to the fact that & is already used in a somewhat different way in existing code:

  • There are some theoretical edge cases in which it could have surprising results. Essentially, when someone puts a pipe inside a capture, this is always turned inside-out by CapturePipe (because that’s how it works) and in certain cases this might lead to unexpected behaviour.
  • The formatter formats the original source code and has no clue that & will be shuffled around, so it will very much clobber the pipelines that contain it.

Magritte has neither of these disadvantages. I personally do not like using ... as chosen ‘fill in’ argument that much because it is used in many other programming languages to stand for multiple (e.g. variadic) arguments. I’d definitely be a proponent of using &_. This still does need some thought (unless a new dedicated token is added to Elixir for it) because while foo(1, &_, 3) works fine, &_ + 2 will be parsed as if it was the (nonsensical) capture &(_ + 2). Maybe there is a way to deal with this gracefully, I don’t know at this time.

hauleth

hauleth OP

I was also thinking about ^_ which would bind stronger than &_, but would be surprising behaviour once again, as it is “non standard” usage of ^ operator.

hauleth

hauleth OP

For anyone interested, I have created small GitHub Poll about which is the preferred operator for such “here be dragons” behaviour in |>:

https://github.com/hauleth/magritte/pull/1

I would :heart: to hear your opinions.

shd42

shd42

Since it’s directly related to the capture operator, i’d argue that anything who doesn’t contain & would cause more confusion, after all, it’s an “extension” of the current behavior, so it should stay on track with what it uses now. I’m not sure that i’d like &_, but at least, it keeps consistency with the overall use of this operator.

Note: I’ve clicked on ... in your poll, because i didn’t realise it would not open a page for me to select an option :face_savoring_food:, but my vote goes for &_.

josevalim

josevalim

Creator of Elixir

I like ... honestly. & is already overloaded, so sometimes I worry about adding new meanings. ... is relatively safe, doesn’t cause precedence issues, and is unlikely to be used as a variable.

11
Post #7
hauleth

hauleth OP

Thanks for pointing this out, I have added the info in top post.

That was my reasoning for this choice as well. I just wanted to know what others think about it.

shd42

shd42

To me, this is simply a consistency point of view, it really looks like using a completely different operator, with “only” the objective of extending the capabilities of what’s already there. It’s like having two different syntax to, in the end, do something quite similar to what the capture operator already does, hence why i though that using something like &_ was a better idea.

The & issues means that it’s better to just put it out of the options ?

lud

lud

... could be a variable !?

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews