map()
map<
Input,Output,ErrorOutput>(mapper,errorMapper?):OperatorFunction<Input,Output|ErrorOutput>
Defined in: src/Map.ts:31
Creates an operator that transforms every item with mapper.
If mapper throws and an errorMapper is given, the value returned by
errorMapper is emitted instead and the iteration continues. Without an
errorMapper the error is rethrown to the consumer.
Type Parameters
Input
Input
Output
Output
ErrorOutput
ErrorOutput = never
Parameters
mapper
(input) => Output | Promise<Output>
transforms an item; may be asynchronous
errorMapper?
(input, error) => ErrorOutput | Promise<ErrorOutput>
turns an error thrown by mapper into a value; may be asynchronous
Returns
OperatorFunction<Input, Output | ErrorOutput>
an operator function
Example
const result = await chain([1, 2, 3])
.map(
(n) => {
if (n === 2) {
throw new Error("two");
}
return n * 10;
},
(n) => -n,
)
.toArray();
// => [10, -2, 30]