3 ms·
To do the things I wanted to do I needed reduce and I think there's no documentation for it. It took me a while to understand the code: ls | map (f: f.size
by t43562 3y ago
To do the things I wanted to do I needed reduce and I think there's no documentation for it. It took me a while to understand the code:
ls | map (f: f.size) | red + # this adds all the file sizes together
one can also use lamdas:
ls | map (f: f.size) | red (lambda acc,y: (y if not acc else acc+y))
(this does the same thing - adds up the file sizes)
BUT: how would I then divide the result by 1024? .... or assign the result to a variable?
There are a number of other functions one can use with "red" like concat, * (times), max, min, count, and, or and a few more.
At the moment I feel like I'm playing with a very fun toy that might give up on me at any moment and turn out to be limited. It obviously has limits but I'm really enjoying it.
- geophile 3y agoJust continue the pipeline, e.g. ls | map (f: f.size) | red + | map (size: size / 1024) You can also leave off "map", so: ls | (f: f.size) | red + | (size: size / 1024) A pipeline produces a stream, so there's no clean way to get the single int result in a variable, but you can store the stream (containing the int) into a variable: ls | ... | (size: size / 1024) >$ x Now x has the stream. To read back the stream and print it: x <$ To do something else with the stream: x <$ (n: n * 1000) etc.