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
38 KiB
38 KiB
title, excerpt, layout
| title | excerpt | layout |
|---|---|---|
| reduce | Take a starting value. Then, for each element of an array, calculate the next value, | manual |
Take a starting value. Then, for each element of an array, calculate the next value,
using the previous value and the element.
reduce(array: [u64], start: Sketch, reduce_fn: FunctionParam) -> Sketch
Arguments
| Name | Type | Description | Required |
|---|---|---|---|
array |
[u64] |
Yes | |
start |
Sketch |
A sketch is a collection of paths. | Yes |
reduce_fn |
FunctionParam |
Yes |
Returns
Sketch - A sketch is a collection of paths.
Examples
fn decagon = (radius) => {
step = 1 / 10 * tau()
sketch001 = startSketchAt([cos(0) * radius, sin(0) * radius])
return reduce([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], sketch001, (i, sg) => {
x = cos(step * i) * radius
y = sin(step * i) * radius
return lineTo([x, y], sg)
})
}
decagon(5.0)
|> close(%)