Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Umbrella] std/collections #1065

Closed
6 of 26 tasks
kt3k opened this issue Jul 27, 2021 · 10 comments
Closed
6 of 26 tasks

[Umbrella] std/collections #1065

kt3k opened this issue Jul 27, 2021 · 10 comments

Comments

@kt3k
Copy link
Member

kt3k commented Jul 27, 2021

We landed the initial version of std/collections at #993

This issue is the umbrella issue for the remaining 28 APIs, which still need discussion. More detailed type definitions / docs / examples are available in the original proposal PR by @LionC.

ARRAYS

Transformations to Array

Transformations to value

Number array transformations

Transformations to other formats

RECORDS

Predicates

  • includesValue

Transformations to Records

Groups

  • reduceGroups
  • aggregateGroups

If you're interested in some specific items in the above, please pick one or more items, create a separate issue/PR for them, and keep discussion there.

@getspooky
Copy link
Contributor

sounds good to me 👍🏼

@lowlighter
Copy link
Contributor

I'm tempted to implement deepMerge but I saw some concerns about it in the mentioned discussion.
Is it still revelant ?

@grian32
Copy link
Contributor

grian32 commented Aug 6, 2021

I would like to attempt implementing sumOf is there any issues with that particular function or am i good to go?

@LionC
Copy link
Contributor

LionC commented Aug 6, 2021

I would like to attempt implementing sumOf is there any issues with that particular function or am i good to go?

I would say just open the PR and if there are comments they will be posted there. Look at the ither functions for implementation and test reference, a lot can be copied as a template :-)

@majidsajadi
Copy link
Contributor

do we really need average function? we can achieve this with a one-liner.

array.reduce((a, b) => a + b) / array.length

@LionC
Copy link
Contributor

LionC commented Aug 20, 2021

do we really need average function? we can achieve this with a one-liner.

array.reduce((a, b) => a + b) / array.length

There is a PR for a separate math mofule that contains average together with other functions.

A lot of things can be achieved with a one liner if you put enough things in a line, which does not necessarily mean that it is the most expressive, obvious, clear or often even known way to do it. See the math/statistics module PR for more info, average will not be in collections

@majidsajadi
Copy link
Contributor

do we really need average function? we can achieve this with a one-liner.

array.reduce((a, b) => a + b) / array.length

There is a PR for a separate math mofule that contains average together with other functions.

A lot of things can be achieved with a one liner if you put enough things in a line, which does not necessarily mean that it is the most expressive, obvious, clear or often even known way to do it. See the math/statistics module PR for more info, average will not be in collections

I suggest that because we removed a lot of the proposed functions from the original PR. ref to this comment: #978 (comment)

@NotFounds
Copy link
Contributor

I would like to implement single, is there any issue with this function?

@LionC
Copy link
Contributor

LionC commented Aug 26, 2021

I would like to implement single, is there any issue with this function?

I would just add the pointer that including (it) => true as a default for the predicate should be considered - that is what kt does because it allows a very smooth and readable transition from an (assumed) single-element array into that single element while also forcing you to handle what happens when that assumption is wrong:

// Assuming some cli that expects exactly one argument

const target = single(Deno.args)
    ?? error("Expected exactly one argument")

doMagic(target)

Also a note on the implementation: Make sure to short circuit when finding a second match instead of iterating through the rest of the array :-)

@kt3k
Copy link
Member Author

kt3k commented Aug 27, 2021

The rest of items will be tracked in #1173.

Thanks @LionC for taking over the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants