stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

feat: adds new group list function

Open dennisschroeder opened this issue 1 year ago • 5 comments

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)])
  ])

dennisschroeder avatar Jul 05 '22 14:07 dennisschroeder

Thx ... sure, I will refactor it and push the changes.

dennisschroeder avatar Jul 09 '22 13:07 dennisschroeder

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.

dennisschroeder avatar Jul 09 '22 13:07 dennisschroeder

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.

lpil avatar Jul 10 '22 17:07 lpil

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.

dennisschroeder avatar Jul 11 '22 06:07 dennisschroeder

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.

lpil avatar Jul 15 '22 20:07 lpil

Closing due to inactivity. Please feel free to reopen.

lpil avatar Sep 15 '22 11:09 lpil