slicy
rzgrep
Our great sponsors
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
slicy
-
When to Use Generics
My personal experience with generics was to port a parallel circular queue library (used to take interface{} and require a type cast at every use) add an experiment to build all the Lodash slice and collection functions in Go.
Happy to say that both worked really well. Took me less than an hour to understand the system enough for these purposes, and the implementation hides neatly in the library - the code that uses the library has absolutely no mention of anything generic. Having generics also helped switch to cleaner implementation inside as well, because I could now use maps as well without type casts.
Looks like a solid useful system - I could do everything I wanted, all the complexity stays in the library, and changes were pretty minimal and easy to understand. Would recommend.
https://github.com/sudhirj/cirque
https://github.com/sudhirj/slicy
- Generic slice/collection utility methods for Go
rzgrep
-
When to Use Generics
I think so, too, but only because that’s idiomatic go. In general, it’s not a good idea to have functions that logically return a value or an error return a value and an error. If you use go, that’s what you do, though.
I see that that was changed already (https://github.com/MoserMichael/rzgrep/commit/764b9ad61a5dbe...)
I think I would not return “ctx.data[0]” for the value returned in case of error, though, but either
- a fresh new instance of T
- a special instance of T created once
The first is cleanest, but may not be performant if creating T’s is costly.
The second may be risky if the returned items are mutable and the caller changes them.
What are some alternatives?
slice - Type-safe functions for common Go slice operations
pie - 🍕 Enjoy a slice! A utility library for dealing with slices and maps that focuses on type safety and performance.
Koazee - A StreamLike, Immutable, Lazy Loading and smart Golang Library to deal with slices.
cirque - A circular queue that processes jobs in parallel but returns results in FIFO
linq-in-go - LINQ to Objects in Go by generic higher order functions