(no title)
andolanra | 4 years ago
func getTopUsers(posts []Post) []UserLevelPoints {
return posts.GroupBy(func (v Post) string { return v.Level })
.Values()
.Map(getTopUser)
}
This pipeline style is significantly easier to read (especially without having to put all those extraneous type parameters in your call to compose3!) and doesn't actually lose any of the core advantages of the functional style: purity, testability in isolation, equational reasoning, and so forth. Sure, the Haskell equivalent might use composition… but composition reads more or less naturally in Haskell, and I don't think it does at all here in Go. If your specific approach to "functional programming" makes your code theoretically easier to reason about but practically harder to both read and write, then is it really helping you much?
platinumrad|4 years ago
pharmakom|4 years ago
mappu|4 years ago
Maybe Haskell and F# can elide this kind of thing, but it's not something the Go compiler is going to do.
Yoric|4 years ago
unknown|4 years ago
[deleted]
Serow225|4 years ago
mjburgess|4 years ago
I'm often think FP-first (data science) -- here though, I was surprised by how I went back over the imperative alternative.
Avoiding `append()` isnt worth it in a language where this level of annotation is required to do FP. It's less clear.
unknown|4 years ago
[deleted]