0

I'm trying to do this in ReasonML without success. The problem is that I don't know the object keys.

const items = {
  foo: () => 'ok',
  bar: () => 'ok2'
};

const result = Object.keys(items).reduce((acc, key) => ({
  ...acc, [key]: items[key]() 
}), {});

console.log(result);
glennsl
  • 28,186
  • 12
  • 57
  • 75
norvana
  • 45
  • 3

1 Answers1

-1

It is possible, but I don't see why List.fold_left should be a requirement. Js.Dict.map is much more appropriate:

let items = Js.Dict.fromList([
  ("foo", () => "ok"),
  ("bar", () => "ok2")
]);

let result = items |> Js.Dict.map([@bs] f => f());
glennsl
  • 28,186
  • 12
  • 57
  • 75