Skip to main content

$pMap

$pMap(array, function) -> array
Compact type signature<af>
Execution
Works with async supplied functionsCan run in parallel

This helper runs many items with a supplied function in parallel. The supplied function can do async work. See Parallelism And Async Evaluation and Async And Concurrency.

Source: FUME

Documentation

$pMap() runs a supplied function across the input collection and returns the mapped results in the original input order.

The supplied function may perform async work, and independent items can run together. See Parallelism And Async Evaluation for the execution model and Async And Concurrency for related helpers.

If the first argument is not already an array, FUME treats it as a one-item sequence. $pMap() waits for all mapping calls to settle, preserves the original ordering in the returned sequence, and omits mapped results that are undefined.

Use $pMap() when the mapper may perform async work and ordering still matters, but the items do not need to be processed sequentially. If the branch list is fixed at authoring time, an array constructor is the simpler static alternative. Use $pLimit() instead when you need to cap concurrency.

Examples

Map in parallel and drop undefined results

Input

This example uses the claims-lines example input. The expression keeps only the higher-allowed lines, but still uses $pMap() so the callback output shape is explicit.

Example input

JSON
[
{
"claimId": "clm-2001",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 110,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2001",
"lineNumber": 2,
"serviceCode": "PROC-020",
"serviceDisplay": "imaging study",
"units": "1",
"unitPrice": 350,
"allowedAmount": 300,
"modifiers": [
"MOD-B",
"MOD-C"
]
},
{
"claimId": "clm-2001",
"lineNumber": 3,
"serviceCode": "PROC-030",
"serviceDisplay": "lab panel",
"units": 2,
"unitPrice": 40,
"allowedAmount": 70,
"modifiers": []
},
{
"claimId": "clm-2002",
"lineNumber": 1,
"serviceCode": "PROC-010",
"serviceDisplay": "office visit",
"units": 1,
"unitPrice": 125,
"allowedAmount": 115,
"modifiers": [
"MOD-A"
]
},
{
"claimId": "clm-2002",
"lineNumber": 2,
"serviceCode": "PROC-040",
"serviceDisplay": "counseling",
"units": 3,
"unitPrice": 60,
"allowedAmount": 150,
"modifiers": [
"MOD-D"
]
}
]

Expression

$pMap($, function($l) { $l.allowedAmount >= 150 ? $l.claimId & "-" & $string($l.lineNumber) : undefined })

Result

[
"clm-2001-2",
"clm-2002-2"
]