Previously variable declaration required a keyword, e.g. ```kcl let x = 4 const x = 4 var x = 4 ``` These were all valid, and did the exact same thing. As of this PR, they're all still valid, but the KCL formatter will change them all to just: ```kcl x = 4 ``` which is the new preferred way to declare a constant. But the formatter will remove the var/let/const keywords. Closes https://github.com/KittyCAD/modeling-app/issues/3985
91 KiB
91 KiB
title, excerpt, layout
| title | excerpt | layout |
|---|---|---|
| map | Apply a function to every element of a list. | 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)]
map(array: [KclValue], map_fn: FunctionParam) -> [KclValue]
Arguments
| Name | Type | Description | Required |
|---|---|---|---|
array |
[KclValue] |
Yes | |
map_fn |
FunctionParam |
Yes |
Returns
Examples
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, 2, 3], drawCircle)
r = 10 // radius
// Call `map`, using an anonymous function instead of a named one.
circles = map([1, 2, 3], (id) => {
return startSketchOn("XY")
|> circle({ center: [id * 2 * r, 0], radius: r }, %)
})