stdlib
stdlib copied to clipboard
feat: adds new group list function
Takes a list and groups the values by a key which is built from a key_selector function and the values are stored in a new List.
Example
[Ok(3), Error("Wrong"), Ok(200), Ok(73)]
|> group(with: fn(i) {
case i {
Ok(_) -> "Successful"
Error(_) -> "Failed"
}
})
|>
should.equal([
#("Failed", [Error("Wrong")]),
#("Successful", [Ok(3), Ok(200), Ok(73)])
])
Thx ... sure, I will refactor it and push the changes.
Hmmm ... I cannot import the map module due to a import cycle error:
error: Import cycle
The import statements for these modules form a cycle:
┌─────┐
│ gleam/map
│ ↓
│ gleam/list
│ ↓
│ gleam/option
└─────┘
Gleam doesn't support dependency cycles like these, please break the
cycle to continue.
OK, sounds like we will need to keep it in the list module and instead make the map module not use the list module. Will be a bit larger of a job.
Oh no ... my comment here was related to the version in the list module. I am now refactoring it into the map module. Like we talked about it on discord.
Sorry, I thought we said it would be best to have it in the list module? Because having it in the map module did not resolve the original import cycle. I think if we have to resolve a cycle either way it would be preferable to have it in list as that is the input type of the function.
Closing due to inactivity. Please feel free to reopen.