Right, take two. Good evening, NixVegas. I will be talking about the Nix Pipe Operator today. But before we get started, can I get a show of hands? How many of you here don't use Nix? Okay, that's nobody. That's good. And how many of you have had experience with some other functional language before Nix? I assume, like, most of you. It's not me, though. My first proper functional language experience was with Nix. And as you can imagine, all the parentheses, they are very scary. Right, so who am I? You might know me on GitHub as illustris. I'm an Nix user since 2020. I'm one of the shepherds of the RFC 0148. That's trying to introduce the Pipe Operator. Right, so today's goal is to introduce it to anybody who is not familiar with it and to get people to engage in the RFC process and get that moving. Right, so the problem with Nix, or the problem I'm going to talk about with Nix, is, well, you can see it right here, right? If I'm trying to figure out what this snippet of code does, I have to look all over the place. First I have to find the object that it's operating on, which is my list. Right, that's somewhere in the middle. It's in the middle to the right. Then I have to see, okay, it's applying built-ins on map on that, and then it's applying a filter, then it's applying built-ins on 2G site. Right, so you kind of have to look all over the place to try and figure out what this snippet is doing. Now, I used to write a lot of Bash. I still do to a great extent, and I'm very much used to thinking left to right, you know, pipe this to that to that. So, this is kind of what the pipeline operator will let you achieve. You've got your value, my list. It doesn't have to be a value. I mean, a function is also a value in mix, I guess. But yeah, that value gets piped from one function to another. So you take my list, you do built-ins on map, X, X into 2, multiply it, then you do a filter, greater than 5, to JSON. Right, same thing, much cleaner, much easier to follow. You can follow the flow of data from one function to another. Right, so how it works, the pipe operator, the way it is implemented right now, is vertical pipe, right angle bracket. There is also a converse left pipe operator, which is left angle bracket, vertical pipe. And what that does is, it just makes the thing on the right flow to the thing on the left. Right, so let me show you a less trivial example. This is an actual function from one of my flicks, where I need to generate a list of subdirectories, given a directory. So you do get subdir dot slash dot, it should give me a list of absolute next door paths to all the subdirectories in a given directory. So, implementation is this, and again, you kind of have to look all over the place. P is the value that is being passed in, so now I have to look again to the center and to the right to see, okay, P is there, read dot P, then filter attos, then atto names, then map, right? So, this is what that would look like implemented with pipes. Much easier to read, I've got the same comments, it's just so much easier to just follow along. Now, some of you who really know Nix and NixPKGs might say, but lib dot pipe already exists, why are you not just using that? So, this is what the lib dot pipe implementation would look like. Lib dot pipe lets you do pipe, value, and then a list of functions to apply. But there are some limitations to that, such as... Right, so, there are still external macros, there are error messages which are a bit harder to deal with. It's not very discoverable, like, I didn't know that lib dot pipe existed until the RSE for the pipe operator came out. And once I saw it, I started using it whenever I needed compatibility with existing Nix functions. But, the biggest problem I see with it is that it's not lazy. What do I mean by that? Let me show an example. So, I'm defining a couple of functions here, f and g, and you can see that whenever they're evaluated, they will print f and g, and when their insides are evaluated, you'll see these things printed as well, g body and f body. Right, so, typical Nix style, if I do f false, g null, f is just selecting. Like, it's an optional call. If the condition is true, then it will evaluate g, it will print the second argument, which in this case is an application of g on null. Right, and you can see that it just prints f. Like, here, it short-circuits, it just sees that there's a false, the option evaluates to false, so it just prints an empty list. However, if we try to do the same thing with the pipe operator, you can see that it's doing so much more. And this, the biggest place I saw this, in fact, was, there are some lakes where I've got lots of Nix OS machines, and they are kind of generated programmatically by iterating over a list of things, and in those situations, if I have to go into a machine and evaluate a single attribute from that, it will have to evaluate the entire set of machines for no reason. The pipe operator, the way it's implemented right now, behaves exactly the same as just regular function composition. Right, so, more reasons for why a native implementation is needed. Availability everywhere, you don't need to import Nix PPGs. It's more discoverable because it's a part of the language, it performs better, and the syntax, in my opinion, looks cleaner. The current status of this is that it's implemented in Nix PPGs as an experimental feature, you can enable it just like Lakes with a flag, and you can use it today in your configs. Now, what do we need from the community? We need real-world usage feedback, we need more people to try it out, to discover edge cases, anything that's not accounted for so far, and to put it back in the RFC thread. And we need community consensus on various design decisions. A bunch of people have just gotten together and made some decisions, including me, and we probably made some mistakes along the way, so feedback is appreciated. I'll just briefly go over some of the design decisions as well. It has no residence and function application. So if you're doing something like... I guess the most significant impact of that is you can't just have in the middle of a pipe x colon x plus one or something like that without brackets. It allows natural chaining, and there are two versions, left and right. Personally, I've only used the right apply operator, but there are some people arguing for left as well. Join in on the discussion if you have any opinions on that. Right, so yeah. One very important design pattern that I've started to rely on with the introduction of pipes is if I've got a long pipe where multiple transformations are being applied, and something's breaking in between, I can just stick a trace file in between. So pipe fx, pipe fy, I can just put a pipe trace file in between to see what's being sent from function x to function y. So for power users, again, better composition patterns, more maintainable code, reduces parenthesis fatigue. Although, again, that last one might be a me problem more than anything else. Comparison with other languages. Lots of other languages have pipes. Bash, of course, we all know. Elixir, Fsharp, OCaml, Elm... I believe Haskell also has a dot operator. Extra-experimental features. Pipe operator. You can grapple it right now on your Nix machines. As long as your Nix is relatively new, it should work. And here's a link. That's a link to the RFC. So try it out. And if you have any thoughts, please join in on the discussion. That's the end of that. Thanks everyone. Any questions? Thank you.