start	end	text
2170	5230	Right, take two.
5230	6950	Good evening, NixVegas.
7190	11030	I will be talking about the Nix Pipe Operator today.
11150	14410	But before we get started, can I get a show of hands?
14410	17550	How many of you here don't use Nix?
18730	20550	Okay, that's nobody.
20550	21330	That's good.
21330	26450	And how many of you have had experience with some other functional language before Nix?
26930	29730	I assume, like, most of you.
29730	31510	It's not me, though.
31510	34590	My first proper functional language experience was with Nix.
34770	38730	And as you can imagine, all the parentheses, they are very scary.
43260	45400	Right, so who am I?
45500	48640	You might know me on GitHub as illustris.
48640	50620	I'm an Nix user since 2020.
50620	53780	I'm one of the shepherds of the RFC 0148.
53780	56160	That's trying to introduce the Pipe Operator.
57020	66060	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.
67280	75800	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?
75800	80080	If I'm trying to figure out what this snippet of code does, I have to look all over the place.
80080	83080	First I have to find the object that it's operating on, which is my list.
83080	84420	Right, that's somewhere in the middle.
84420	86140	It's in the middle to the right.
86140	91680	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.
91740	98100	Right, so you kind of have to look all over the place to try and figure out what this snippet is doing.
100020	103520	Now, I used to write a lot of Bash.
103600	109380	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.
113460	118660	So, this is kind of what the pipeline operator will let you achieve.
118660	121540	You've got your value, my list.
121700	123000	It doesn't have to be a value.
123000	125960	I mean, a function is also a value in mix, I guess.
126300	129840	But yeah, that value gets piped from one function to another.
129840	137180	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.
137180	140140	Right, same thing, much cleaner, much easier to follow.
140140	143200	You can follow the flow of data from one function to another.
146640	154320	Right, so how it works, the pipe operator, the way it is implemented right now, is vertical pipe, right angle bracket.
154320	159500	There is also a converse left pipe operator, which is left angle bracket, vertical pipe.
159860	163860	And what that does is, it just makes the thing on the right flow to the thing on the left.
166860	170660	Right, so let me show you a less trivial example.
170740	177600	This is an actual function from one of my flicks, where I need to generate a list of subdirectories, given a directory.
177600	184920	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.
185300	189760	So, implementation is this, and again, you kind of have to look all over the place.
190080	201160	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?
202380	206900	So, this is what that would look like implemented with pipes.
207420	212220	Much easier to read, I've got the same comments, it's just so much easier to just follow along.
213860	221180	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?
221800	224960	So, this is what the lib dot pipe implementation would look like.
225240	231980	Lib dot pipe lets you do pipe, value, and then a list of functions to apply.
233400	236180	But there are some limitations to that, such as...
241940	250660	Right, so, there are still external macros, there are error messages which are a bit harder to deal with.
250660	256980	It's not very discoverable, like, I didn't know that lib dot pipe existed until the RSE for the pipe operator came out.
257020	261880	And once I saw it, I started using it whenever I needed compatibility with existing Nix functions.
262380	266080	But, the biggest problem I see with it is that it's not lazy.
266260	267440	What do I mean by that?
267440	269260	Let me show an example.
270860	284960	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.
285080	290840	Right, so, typical Nix style, if I do f false, g null, f is just selecting.
290840	294180	Like, it's an optional call.
294680	306440	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.
306740	308740	Right, and you can see that it just prints f.
308740	318120	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.
319140	324640	However, if we try to do the same thing with the pipe operator, you can see that it's doing so much more.
324780	342100	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,
342100	345520	it will have to evaluate the entire set of machines for no reason.
347260	352560	The pipe operator, the way it's implemented right now, behaves exactly the same as just regular function composition.
354400	359300	Right, so, more reasons for why a native implementation is needed.
360980	363380	Availability everywhere, you don't need to import Nix PPGs.
363740	370220	It's more discoverable because it's a part of the language, it performs better, and the syntax, in my opinion, looks cleaner.
370800	382420	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.
383280	388180	Now, what do we need from the community?
388180	398960	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.
398960	402040	And we need community consensus on various design decisions.
402040	410840	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.
411640	414420	I'll just briefly go over some of the design decisions as well.
414860	417660	It has no residence and function application.
419040	422080	So if you're doing something like...
422080	429760	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.
430400	434680	It allows natural chaining, and there are two versions, left and right.
434880	440320	Personally, I've only used the right apply operator, but there are some people arguing for left as well.
440320	443000	Join in on the discussion if you have any opinions on that.
444540	446140	Right, so yeah.
454380	469240	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.
469240	476660	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.
481060	487680	So for power users, again, better composition patterns, more maintainable code, reduces parenthesis fatigue.
487780	491360	Although, again, that last one might be a me problem more than anything else.
492980	494380	Comparison with other languages.
494380	496600	Lots of other languages have pipes.
496600	498260	Bash, of course, we all know.
498380	501400	Elixir, Fsharp, OCaml, Elm...
501400	503940	I believe Haskell also has a dot operator.
507360	508640	Extra-experimental features.
508640	509420	Pipe operator.
509420	511660	You can grapple it right now on your Nix machines.
511660	514780	As long as your Nix is relatively new, it should work.
516220	517380	And here's a link.
517480	518880	That's a link to the RFC.
518960	519880	So try it out.
519880	522400	And if you have any thoughts, please join in on the discussion.
531230	532490	That's the end of that.
532490	533430	Thanks everyone.
533430	534510	Any questions?
535650	536270	Thank you.
