* Automatic fixing of deprecations and use non-quoted default planes by default Signed-off-by: Nick Cameron <nrc@ncameron.org> * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 * A snapshot a day keeps the bugs away! 📷🐛 --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
60 lines
85 KiB
Markdown
60 lines
85 KiB
Markdown
---
|
|
title: "map"
|
|
excerpt: "Apply a function to every element of a list."
|
|
layout: manual
|
|
---
|
|
|
|
Apply a function to every element of a list.
|
|
|
|
Given a list like `[a, b, c]`, and a function like `f`, returns `[f(a), f(b), f(c)]`
|
|
|
|
```js
|
|
map(
|
|
array: [KclValue],
|
|
mapFn: FunctionSource,
|
|
): [KclValue]
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `array` | [`[KclValue]`](/docs/kcl/types/KclValue) | | Yes |
|
|
| `mapFn` | `FunctionSource` | | Yes |
|
|
|
|
### Returns
|
|
|
|
[`[KclValue]`](/docs/kcl/types/KclValue)
|
|
|
|
|
|
### Examples
|
|
|
|
```js
|
|
r = 10 // radius
|
|
fn drawCircle(id) {
|
|
return startSketchOn(XY)
|
|
|> circle(center = [id * 2 * r, 0], radius = r)
|
|
}
|
|
|
|
// Call `drawCircle`, passing in each element of the array.
|
|
// The outputs from each `drawCircle` form a new array,
|
|
// which is the return value from `map`.
|
|
circles = map([1..3], drawCircle)
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
r = 10 // radius
|
|
// Call `map`, using an anonymous function instead of a named one.
|
|
circles = map([1..3], fn(id) {
|
|
return startSketchOn(XY)
|
|
|> circle(center = [id * 2 * r, 0], radius = r)
|
|
})
|
|
```
|
|
|
|

|
|
|
|
|