I think shoehorning fp onto go just results in people having a wrong first impression of fp, damaging them for years or forever. fp is so much more than map, filter and reduce.
I've tried going down this route myself by using libraries like fp-go[1]. I think this particular project has done a great job, but I ultimately opted not to pursue functional programming in Go for a few reasons:<p>- Ergonomics weren't the greatest when working with monads such as options and results. I think pattern matching is needed here, but concepts like those go against Go's core design philosophy.<p>- I suspect there are several cases where runtime performance is an issue, but admittedly did not investigate this.<p>- Perhaps most importantly, it deviates from the way most people read and write Go, and less importantly, LLMs struggle too.<p>Because of these reasons, I came to the conclusion that the advantages were not worth the trade-offs.<p>Perhaps somebody will create a garbage-collected Rust-like language in the future and bridge the gap between the two languages.<p>[1] - <a href="https://github.com/IBM/fp-go">https://github.com/IBM/fp-go</a>
Function operations are possible in Go like it’s possible in any language that define function in the syntax. But functional programming goes beyond functions, and Go was not designed to support it.<p>I’m a fan of Go and FP and would love to see someone bridge other FP aspects like monads, in a way that feels natural in Go.
I think there is a genuine tension between languages that can do functional and languages that are functional. Sometimes having functional there as one of the tools, but not the only tool, is best.<p>For example raku (and perl before it) has very good support with map/grep/closures, etc.<p><a href="https://rakujourney.wordpress.com/2024/10/12/raku-burritos/" rel="nofollow">https://rakujourney.wordpress.com/2024/10/12/raku-burritos/</a><p>Says…<p>And let’s end with a quote (sadly I did not record the originator)…<p>I think i just expressed my thought in a wrong way, haha. I am a functional freak, and the first thing i did was check out Raku’s functional patterns. I was amazed. Raku can be extremely functional, but in my opinion language can be called functional when there’s no other way other than functional for the most part. Raku has great functional support, but the language doesn’t force you into anything, you can do basically anything! A sandbox language, and i am loving it.<p>anon
Take a look at the Ginkgo testing framework to see the horrors of shoe horning FP into Go<p><a href="https://onsi.github.io/ginkgo/#writing-specs" rel="nofollow">https://onsi.github.io/ginkgo/#writing-specs</a>
Hey, I wrote a book with that exact same title as the blog post.. :) not sure if HN frowns upon this kind of self-advertising in comments, but well.. you can find it on Amazon / Packt, if you are interested lol