Skip to content

New named parameters to .classify #6

Open

Description

@FCO

Id like to suggest to add:

  • :&reduce
  • :&produce
  • :$initial-value

so,

^10.classify: * %% 2, :reduce(&[+])

would return

{True => 25, False => 20}

,

^10.classify: * %% 2, :produce(&[+])

would return

({}, {True => 0}, {True => 0, False => 1}, {True => 2, False => 1}, {True => 2, False => 4}, {True => 6, False => 4}, {True => 6, False => 9}, {True => 12, False => 9}, {True => 12, False => 16}, {True => 20, False => 16}, {True => 20, False => 25}).Seq

and

^5.classify: * %% 2, :produce(-> %agg, $i { %agg{$i} = <a e i o u>[$i]; %agg }), :initial-value{}

would return

{True => {0 => "a", 2 => "I", 4 => "u"}, False => {1 => "e", 3 => "o"}}

That would also be interesting to add the :$initial-value (or with any name) to .reduce and .produce

Activity

  1. AlexDaniel commented on Apr 5, 2019

    @AlexDaniel
    Member

    And which problem are we trying to solve here exactly?

  2. FCO commented on Apr 5, 2019

    @FCO
    ContributorAuthor

    I had to do that by hand some times, and ended up not using classify because it would be worst to write and have to loop throw each key and reduce each value (on reduce case)... making the classify do that, you can reduce/produce iterating only once...

  3. Altai-man commented on Apr 5, 2019

    @Altai-man
    Member

    Why not just:

    > (^10).classify(* %% 2).map({ .key => [+] .value })
    (False => 25 True => 20)
    

    for the first one? Because it adds some symmetry with produce?

  4. FCO commented on Apr 5, 2019

    @FCO
    ContributorAuthor

    It iterates twice each element...

    and what about multi level classify?

  5. AlexDaniel commented on Apr 5, 2019

    @AlexDaniel
    Member

    Do we have some examples of this functionality being used/implemented in real code? Maybe in the ecosystem?

  6. jnthn commented on Apr 5, 2019

    @jnthn
    Contributor

    Does this proposal apply to categorize also?

  7. jnthn commented on Apr 5, 2019

    @jnthn
    Contributor

    That would also be interesting to add the :$initial-value (or with any name) to .reduce and .produce

    How would this interact with the current semantics of things like [+] () and [+] 1, which use multi-dispatch on the target operator?

    Further, how is it better than (flat $initial-value, @values).reduce(&reducer)?

  8. AlexDaniel commented on Apr 5, 2019

    @AlexDaniel
    Member
  9. lizmat commented on Jan 13, 2025

    @lizmat
    Collaborator
  10. added
    Next Resolutions MeetingThis issue will be reviewed in a future Resolutions Meeting, possibly the next
    on Jan 13, 2025
  11. removed
    Next Resolutions MeetingThis issue will be reviewed in a future Resolutions Meeting, possibly the next
    on Jan 8, 2026
  12. lizmat commented on Feb 22, 2026

    @lizmat
    Collaborator

    @FCO is this still something that would need to be pursued this way?

    If not, then suggest closing this issue.

  13. FCO commented on Feb 22, 2026

    @FCO
    ContributorAuthor

    I think that is/would be useful. Maybe I should create a module for that to help on the discussion…

  14. lizmat commented on Feb 22, 2026

    @lizmat
    Collaborator

    Going to close this issue in the meantime, ok?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    languageChanges to the Raku Programming Language

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions