Hacker News new | past | comments | ask | show | jobs | submit login

Why reverse the slice at all? Collect the input into a slice, then return an iterator that navigates the slice in backward order.

What this sort of thing lacks is any ability to optimize. For example, let's say the operation is Reverse().Take(20). There's no reason for the reverser to keep more than 20 elements in its buffer. But to express that, you have to make sure the iterator can be introspected and then rewritten to merge the operators and maybe unroll some of the loops to get better cache locality. This is what Haskell can achieve via Stream Fusion, which is pretty neat. But not so viable in Go.




Julia does similar optimizations with the broadcast operator. The results can be mind bogglingly fast.


Thanks, good points.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: