|
|
|
|
|
by nephesh
5029 days ago
|
|
> With a more complex type (I don't see how this would affect one more than the other) It does because the discussion is about generics. The fact that you're writing out types for one and not the other makes your comparisons a bit disingenuous, though I understand if Go isn't very good at functional programming. b) Composing various operations. Composing filter + map: As you keep building them up the imperative style will have more code overhead and less efficiency. > c) Swapping the container type is just a matter of swapping "_, n := range numbers". This isn't true since the functional one could easily swap out to use an infinite data source whereas the imperative will be constrained to the arrays you're already using. |
|
b) No, it will not be less efficient. It's all done within one loop, in-place. You can compose everything inside the body of the loop. A functional language would do the same if it's intelligent.
c) You can easily create an infinite data source in Go with the generator pattern:
numbers := make(chan int); go func() { for i := 0; ; i++ { numbers <- i } }()
for n := range numbers {...}