Skip to content

Extra work/more complicated example in "Maintaining a counter" #92

@LinusU

Description

@LinusU

The current example "Maintaining a counter" seems to be extra convoluted in order to use the new method. I think that this might be a remnant from earlier iterations of the proposal. Right now the code is:

let counts = new Map();
counts.set(key, counts.getOrInsert(key, 0) + 1);

but this code is functionally equivalent, and avoids first inserting 0 only to immediately replace it with 1:

let counts = new Map();
counts.set(key, (counts.get(key) ?? 0) + 1);

It's also shorter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions