Open PEZO19 opened 2 years ago
Cool code golfing! I would accept some PRs for this, as long as we don't do minification of variable names by hand. i.e. keep names as they were and code formatting/indentation as well.
@staltz Okay! I'll do that! :) Would you prefer to see the evolution of the code step by step in a branch or you're only interested in the end result? Also: are you ok with omitting variables? (Reusing a variable for multiple "purposes" if context makes that possible.)
@staltz This one? Shall I change index.js
or make a new file?
const skip = max => source => (start, sink) => {
!start &&
(source(0, (t, d) => {
!t ? (
start = d,
sink(t, d)
) :
t == 1 &&
0 < max-- ?
start(1) :
sink(t, d)
}))
};
@PEZO19 I'd like to at least keep the if
s, unless they are a leaf if
.
@staltz
Hi there! I am not sure how useful this is or how useful it ever can be, but while studying callbags I realized that both the theoretical protocol (using 0,1,2 numbers extensively) and the exact operator implementations (via neat and succinct callbacks) make room together for handmade optimizations. (We used to do such things as homework at the uni, so I know that for many this literally can be fun, I feel that the callbag abstraction truly enables that by its nature.)
I am wondering if that can be useful at scale (more operators) and what kind of performance tests or other things could be created to be really useful - and of course what shall be the target ES version...
I just want to put here an example how I progressed with that (I know some tricks, but I am not a pro in that area), maybe some folks will think it further.
I think we might find quite a lot patterns across operators. A few notes / examples / interesting things:
return
start
variableskipped
andtalkback
variablessink
calls instead 3, unfortunately lost the "bad" example)The right side of the assignment went from
102 chars
:t=>e=>(i,n)=>{if(0!==i)return;let r,s=0;e(0,(e,i)=>{0===e?(r=i,n(e,i)):1===e&&s<t?(s++,r(1)):n(e,i)})}
to74 chars
:i=>s=>(t,c)=>{!t&&(s(0,(s,f)=>{!s?(t=f,c(s,f)):1==s&&0<i--?t(1):c(s,f)}))}
-27%
:)Tests passed, however I realized that omitting the first conditional (originally the
return
part) won't make tests fail, I tried to keep that there though.I used this minifier as a starter: https://skalman.github.io/UglifyJS-online/