Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> It's annoying to rewrite common functional operations (e.g. map, reduce) over and over again with slightly different argument types (or sprinkling type casts all over your code).

Personally I would go with interface{} and type cast.



This isn't viable if it's a performance critical portion of your code.

Idiomatic Go (currently) is to use a for loop for map and reduce/fold operations.


> Idiomatic Go (currently) is to use a for loop for map and reduce/fold operations.

There is going to be a for loop one way or the other. The question is n occurrences of for loop or one occurrence of for loop in a generic_map func followed by n-1 occurrences of call to generic_map and type casting.

As for performance, function calls themselves incur a performance penalty. That doesn't necessitate putting all code inline. If the profiler says that interface{} and type casting incurs a significant performance penalty(it does incur a penalty but does it matter?), then I would go for inline for.




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

Search: