5 ms·
Is there any helper function that convert existing functions into pipe's style? For instance: [1,2,3,4,5] | p(sum) where p would transform a def(seq, args
by d0m 16y ago
Is there any helper function that convert existing functions into pipe's style?
For instance:
[1,2,3,4,5] | p(sum)
where p would transform a def(seq, args, kwargs) to def(args,kwargs) and yield the results?
Also, maybe:
[1,2,3,4,5] >> sum
where that could be made automatically ?
- heyitsnick 16y agoKeep in mind I have no idea how this magical code works. In fact I can't even find the pipe character on my keyboard right now (I am copy and pasting it!). But this seems to work: @Pipe def p(iterable, function, **kwargs): return function(iterable, **kwargs) In [3]: from pipe import * In [4]: [1,2,3,4,5] | p(sum) Out[4]: 15
- yesbabyyes 16y agoOr even just wrap the function in Pipe: >>> from pipe import * >>> [1, 2, 3, 4, 5] | Pipe(sum) 15
- jerf 16y ago"In fact I can't even find the pipe character on my keyboard right now" On standard US keyboards, it's shift-backslash. YLMV.
- lloeki 16y agoOn Mac keyboards it's alt+shift+L. Just in case.
- heyitsnick 16y agoHa thank you! I was typing the pipe character that's in the top left (alt gr + `) that looked the same but is clearly a different character code. It's a bew laptop with a new keyboard layout (US).