Files
modeling-app/docs/kcl/map.md
Nick Cameron df278c7e6a Various hover improvements (#5617)
* Show more info on hover for variables

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Move hover impls to lsp module

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Make hover work on names inside calls, fix doc line breaking, trim docs in tool tips

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Test the new hovers; fix signature syntax

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Hover tips for kwargs

Signed-off-by: Nick Cameron <nrc@ncameron.org>

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
2025-03-04 09:53:31 +00:00

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],
  mapFn: FunctionSource,
): [KclValue]

Arguments

Name Type Description Required
array [KclValue] Yes
mapFn FunctionSource Yes

Returns

[KclValue]

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..3], drawCircle)

Rendered example of map 0

r = 10 // radius
// Call `map`, using an anonymous function instead of a named one.
circles = map([1..3], fn(id) {
  return startSketchOn("XY")
    |> circle(center = [id * 2 * r, 0], radius = r)
})

Rendered example of map 1