5 ms·
Go has lambdas https://go.dev/ref/spec#Function_literals https://go.dev/ref/spec#Function_literals
by ImprobableTruth 5y ago
Go has lambdas
https://go.dev/ref/spec#Function_literals https://go.dev/ref/spec#Function_literals
- eru 5y agoYes, but without generics it's hard to do much useful with lambdas in your statically typed language. You can't even write a filter or map function. And eg Go's old workaround for polymorphic sorting functions was just atrocious: it was rather convoluted, and only really worked at all for in-place sorting.
- Intermernet 5y ago"without generics it's hard to do much useful with lambdas in your statically typed language" I challenge you to read the source for the Go standard library and maintain that position. Lambdas are orthogonal to generics in pretty much every aspect. You need to stop thinking in terms of "filter or map". Programming languages that didn't include these idioms existed long before Go, and will exist long after Go. I welcome the introduction of generics, but I still don't have many places in many code-bases where they'll be used.
- eru 5y agoMap is a pretty fundamental thing you might want to do to your data structures (and more). Look up all the places that Haskell's "Functor" pops up for example. Filter is much more limited in where it's applicable, that's true. In any case, I already gave another example in my comment: sorting. And sorting's API is done terribly in the Go standard libraries. The Go standard library does a lot with callbacks; and yes, it manages to get something useful out of them via something even uglier: mutation.