pmap
Builtin index · Collections & strings
result = map(xs, f)
Input: xs, f · Output: result
What it is
xs is a Vec/List; f is a one-argument function — the function itself (double, sqrt, (x) := x * 2), or a Str naming one you defined.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = map(xs, f) | xs Vec or Listxs is a Vec/List.f Strf is a one-argument function — the function itself (double, sqrt, (x) := x * 2), or a Str naming one you defined. | result List | Returns a List: f applied to every element. The collection comes first, like every other higher-order builtin, which is what makes xs.map(f) and xs |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
extract(x) := x * x
xs = 0 to 9
out = xs |> pmap("extract") # same as pmap(xs, "extract")
print(out) # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
from concurrency
How it works
pmap(xs, fnName) — apply a named function to every element of xs across available_parallelism() threads, same isolation model as parallel for/spawn (share-nothing: each worker gets its own env/funcs snapshot and RNG stream drawn up front from the parent's own stream, for reproducibility) — but shaped as an expression returning a new vector, for the common "apply this pure function to every sample" pipeline stage. xs comes FIRST (not fnName) specifically so |> composes naturally: signals |> pmap("extract_features") is pmap(signals, "extract_features"), matching |>'s own rule that the piped value lands in the first argument slot.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
map — documented in the same entry.