Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
github.com/crosscode-nl/iterator
This project is an implementation of iterators for go using generics. I started this project because I like the functional map/filter/reduce pattern that is offered by many languages.
Go is a simple language - meaning that it is lean in features - but it offers functional principles in the form of closures.
Go did not support generics until version 1.18. Go 1.18.x is at the time of writing (2022-05-06) the latest release version.
I was wondering if Go would now allow us to write a good type safe iterator framework.
I also wanted to evaluate the Gherkin/Cucumber BDD test framework Godog.
Please take a look at the examples in iterators_test.go, and read the API documentation.
Go does not support Generics well enough to allow me to design an intuitive framework.
FromSlice(sliceOfStructs).Map(toString).Filter(oneCharacterStrings).Reduce(mostCommonCharacter)
// This will not compile.
iter := FromSlice([]int{1,2,3,4})
Map(iter, toString)
// This will compile, because we specify the generic type of int when calling the generic Map function.
iter := FromSlice([]int{1,2,3,4})
Map[int](iter, toString)
There are workarounds possible for the second issue, such as:
Returning a generic interface means a struct can only implement that interface closes a lot of doors for future expansion.
Creating a method in each type that returns a generic interface can make the library harder to use, and is not a lot better than just specifying the generic type of the receiving function.
Such a workaround could look like this:
iter := FromSlice([]int{1,2,3,4})
Map(iter.I(), toString)
Instead of:
iter := FromSlice([]int{1,2,3,4})
Map[int](iter, toString)
Also, because there is no support for generic methods means no generic fluent API like constructs are possible.
So, I think the current design is the best design for this library yet and future versions of the Go compiler could have improvements on generics which makes this library automatically friendlier to use.
Godog is awesome.
go test
by using the subtest functionality of Go. So it
will integrate in pipelines already configured for pure go tests.Godog does have some small issues
It is a very usable library. The small issues I encountered where easy to workaround.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.