Gleam: Additional list functions

Created on 14 Apr 2019  路  8Comments  路  Source: gleam-lang/gleam

  • [x] all
  • [x] any
  • [x] at
  • [x] concat
  • [x] index_map
  • [x] intersperse
  • [x] sort
  • [x] unique
  • [x] zip
help wanted

All 8 comments

Hi! This looks like a good first issue to tackle. I'd like to work on it :)

Wonderful! If you have any questions ask them here or in the irc channel. :)

Happy to accept multiple PRs or one big one, whatever works for you.

Is the plan to have a list module to encapsulate these functions?

There is one already! See gleam_stdlib/src/list.gleam

@lpil

1) Is concat meant to return a flattened list? [[1],[2]] -> [1,2] Or, a string? [1,2] -> "12" Or, something else?

2) Can you elaborate on what index_map is meant to be?

3) In what way is any different from contains?

4) Should zip just use Erlang's lists:zip? Or are you interested in a more Haskell style zip where lists do not need to be equal length?

5) Is this the proper interpretation of intersperse? intersperse([1,2,3],4) -> [1,4,2,4,3,4] Or should it return a string?

Oops, I've made a mistake and we don't need concat as we have flatten already.

index_map is map there the mapping function takes two arguments, the element and the index of the element in the list.

Any takes a predicate function and returns true if all the elements in the list return True.

I would prefer zip to not throw an error, so the Haskell behaviour is preferred.

That intersperse example is correct :)

@lpil Any takes a predicate function and returns true if all the elements in the list return True. - Isn't this all?

Sorry, typo on my part. That is indeed all! Any is if at least one returns True for that predicate. contains doesn't take a predicate, instead it just checks for equality against each element.

Was this page helpful?
0 / 5 - 0 ratings