Given a .map function, builds a .map function which throws an error if any mapped elements do not pass a truthyness test.
var data = { foo: 1, bar: 2 };let keys = [ 'foo', 'bar' ]let values = keys.map(assertMap(key => data[key], "Key not found"));// values is [1, 2]let keys = [ 'foo', 'bar', 'baz' ]let values = keys.map(assertMap(key => data[key], "Key not found"));// throws Error("Key not found") Copy
var data = { foo: 1, bar: 2 };let keys = [ 'foo', 'bar' ]let values = keys.map(assertMap(key => data[key], "Key not found"));// values is [1, 2]let keys = [ 'foo', 'bar', 'baz' ]let values = keys.map(assertMap(key => data[key], "Key not found"));// throws Error("Key not found")
Given a .map function, builds a .map function which throws an error if any mapped elements do not pass a truthyness test.
Example