Files
modeling-app/docs/kcl/reduce.md
Adam Chalmers 258bce8adc Rename arrayReduce to reduce (#4030)
I think when we make reduce work with objects,
we'll either keep the same function and make it
polymorphic, or we'll have namespaces/modules and
use Array.reduce and Object.reduce. Either way this
name can be changed.
2024-09-30 20:03:28 -05:00

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) => {
  let step = 1 / 10 * tau()
  let sketch001 = startSketchAt([cos(0) * radius, sin(0) * radius])
  return reduce([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], sketch001, (i, sg) => {
  let x = cos(step * i) * radius
  let y = sin(step * i) * radius
  return lineTo([x, y], sg)
})
}
decagon(5.0)
  |> close(%)

Rendered example of reduce 0