4 ms·
Agree with all the comments like "where are the nd arrays?" BUT, they have list comprehensions!! One of the main things I miss coming from Python.
by chartpath 6y ago
Agree with all the comments like "where are the nd arrays?"
BUT, they have list comprehensions!! One of the main things I miss coming from Python.
- conradludgate 6y agoOnce generics get introduced into the language, you can write a generic map function which can take a []T and a func(T) U to return a []U. While it's not as elegant as a list comprehension, it's nicer than writing a for loop every time. Although, I can't remember what the performance impact of closures are in go, so this might not be a cheap operation.
- jhgb 6y agoWhy not something like a channel map? Give it a channel and a function and you get another channel with a goroutine running in the background.
- nemo1618 6y agoIn practice, no one will do this, unless there happens to be a function with the correct signature already available. The lambda syntax is so verbose that it's easier to just write the for loop. Another problem is that tons of Go functions return (value, error), and it's not clear how such functions should interact with a "map" function. Return all the errors in a separate slice? Stop at the first error? What if you only want to stop when the error is io.EOF? etc. I think we'll only see map/filter/reduce if the language is changed to specifically accommodate them. I've experimented with doing this myself, which people tend to view as heresy: https://twitter.com/lukechampine/status/1367279449302007809?s=19 https://twitter.com/lukechampine/status/1367279449302007809?...
- pjmlp 6y agoEasy, by using monadic operators. https://naveenkumarmuguda.medium.com/railway-oriented-programming-a-powerful-functional-programming-pattern-ab454e467f31 https://naveenkumarmuguda.medium.com/railway-oriented-progra...