KCL stdlib reduce function (#3881)

Adds an `arrayReduce` function to KCL stdlib. Right now, it can only reduce SketchGroup values because my implementation of higher-order KCL functions sucks. But we will generalize it in the future to be able to reduce any type.

This simplifies sketching polygons, e.g.

```
fn decagon = (radius) => {
  let step = (1/10) * tau()
  let sketch = startSketchAt([
    (cos(0) * radius), 
    (sin(0) * radius),
  ])
  return arrayReduce([1..10], sketch, (i, sg) => {
      let x = cos(step * i) * radius
      let y = sin(step * i) * radius
      return lineTo([x, y], sg)
  })
}
```

Part of #3842
This commit is contained in:
Adam Chalmers
2024-09-14 00:10:17 -04:00
committed by GitHub
parent 3cd3e1af72
commit f235a950b0
9 changed files with 7651 additions and 2 deletions

858
docs/kcl/arrayReduce.md Normal file

File diff suppressed because one or more lines are too long