How to handle the case where a function returns a collection?
const ADDR_MAP = new Map();
function GetAddressList() {
const values = [...ADDR_MAP.values()];
return values;
}
Alternatively, we could do something like:
const ADDR_MAP = new Map();
function GetAddresses() {
if (ADDR_MAP.size===0) return undefined;
const values = [...ADDR_MAP.values()];
return values;
}
In this case, undefined is returned if there are no addresses.
I think the first case is probably preferable...we can assume that a GetList operation always returns an array, as well as for Find and Match operations.
However, in the case of a GetItem, we would want to return undefined if it doesn't exist.
How to handle the case where a function returns a collection?
Alternatively, we could do something like:
In this case,
undefined
is returned if there are no addresses. I think the first case is probably preferable...we can assume that a GetList operation always returns an array, as well as for Find and Match operations.However, in the case of a GetItem, we would want to return
undefined
if it doesn't exist.