Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/es6/Stdlib_Dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function forEach(dict, f) {
}

function forEachWithKey(dict, f) {
Object.entries(dict).forEach(param => f(param[1], param[0]));
Object.keys(dict).forEach(key => f(dict[key], key));
}

function mapValues(dict, f) {
let target = {};
forEachWithKey(dict, (value, key) => {
Object.keys(dict).forEach(key => {
let value = dict[key];
Comment on lines +18 to +19
Copy link
Member Author

target[key] = f(value);
});
return target;
Expand Down
5 changes: 3 additions & 2 deletions lib/js/Stdlib_Dict.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function forEach(dict, f) {
}

function forEachWithKey(dict, f) {
Object.entries(dict).forEach(param => f(param[1], param[0]));
Object.keys(dict).forEach(key => f(dict[key], key));
}

function mapValues(dict, f) {
let target = {};
forEachWithKey(dict, (value, key) => {
Object.keys(dict).forEach(key => {
let value = dict[key];
target[key] = f(value);
});
return target;
Expand Down
3 changes: 2 additions & 1 deletion runtime/Stdlib_Dict.res
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ let forEach = (dict, f) => {
dict->valuesToArray->Stdlib_Array.forEach(value => f(value))
}

@inline
let forEachWithKey = (dict, f) => {
dict->toArray->Stdlib_Array.forEach(((key, value)) => f(value, key))
dict->keysToArray->Stdlib_Array.forEach(key => f(dict->getUnsafe(key), key))
}

let mapValues = (dict, f) => {
Expand Down