TodePond / Habitat

my javascript helpers
MIT License
45 stars 5 forks source link

Some sort of auto-keyed Map #58

Closed TodePond closed 2 years ago

TodePond commented 2 years ago
const grid = new KeyedMap()
grid.set([2, 3], "foo")
grid.get([2, 3]) //"foo"

One day the tuple proposal might arrive and replace this. (https://github.com/tc39/proposal-record-tuple)

TodePond commented 2 years ago

Maybe it would be better to have a keying function, then it could be used with regular maps instead.

const grid = new Map()
grid.set(key([2, 3]), "foo")
grid.get(key([2, 3])) //"foo"

Or something funky like...

const grid = new Map()
grid.set(_([2, 3]), "foo")
grid.get(_([2, 3])) //"foo"
TodePond commented 2 years ago

Or maybe...

const grid = new Map()
grid.set(tuple([2, 3]), "foo")
grid.get(tuple([2, 3])) //"foo"
TodePond commented 2 years ago

json.js now covers this