Files
modeling-app/docs/kcl/arrayReduce.md
Jess Frazelle 790af3842c Recusive docs (#4023)
updates



updates



updates



updates



updates



updates



better



updates



array of



updates



updates



updates



updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-09-27 19:50:44 -07:00

38 KiB

title, excerpt, layout
title excerpt layout
arrayReduce 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.

arrayReduce(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 arrayReduce([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 arrayReduce 0