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.
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -19,7 +19,6 @@ layout: manual
|
|||||||
* [`angledLineToX`](kcl/angledLineToX)
|
* [`angledLineToX`](kcl/angledLineToX)
|
||||||
* [`angledLineToY`](kcl/angledLineToY)
|
* [`angledLineToY`](kcl/angledLineToY)
|
||||||
* [`arc`](kcl/arc)
|
* [`arc`](kcl/arc)
|
||||||
* [`arrayReduce`](kcl/arrayReduce)
|
|
||||||
* [`asin`](kcl/asin)
|
* [`asin`](kcl/asin)
|
||||||
* [`assert`](kcl/assert)
|
* [`assert`](kcl/assert)
|
||||||
* [`assertEqual`](kcl/assertEqual)
|
* [`assertEqual`](kcl/assertEqual)
|
||||||
@ -79,6 +78,7 @@ layout: manual
|
|||||||
* [`profileStart`](kcl/profileStart)
|
* [`profileStart`](kcl/profileStart)
|
||||||
* [`profileStartX`](kcl/profileStartX)
|
* [`profileStartX`](kcl/profileStartX)
|
||||||
* [`profileStartY`](kcl/profileStartY)
|
* [`profileStartY`](kcl/profileStartY)
|
||||||
|
* [`reduce`](kcl/reduce)
|
||||||
* [`rem`](kcl/rem)
|
* [`rem`](kcl/rem)
|
||||||
* [`revolve`](kcl/revolve)
|
* [`revolve`](kcl/revolve)
|
||||||
* [`segAng`](kcl/segAng)
|
* [`segAng`](kcl/segAng)
|
||||||
|
47
docs/kcl/reduce.md
Normal file
47
docs/kcl/reduce.md
Normal file
File diff suppressed because one or more lines are too long
7722
docs/kcl/std.json
7722
docs/kcl/std.json
File diff suppressed because it is too large
Load Diff
2
src/wasm-lib/Cargo.lock
generated
2
src/wasm-lib/Cargo.lock
generated
@ -1958,7 +1958,7 @@ dependencies = [
|
|||||||
"regex",
|
"regex",
|
||||||
"regex-syntax 0.8.5",
|
"regex-syntax 0.8.5",
|
||||||
"structmeta",
|
"structmeta",
|
||||||
"syn 2.0.77",
|
"syn 2.0.79",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -97,7 +97,7 @@ async fn call_map_closure<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// For each item in an array, update a value.
|
/// For each item in an array, update a value.
|
||||||
pub async fn array_reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
pub async fn reduce(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||||
let (array, start, f): (Vec<u64>, Sketch, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?;
|
let (array, start, f): (Vec<u64>, Sketch, FnAsArg<'_>) = FromArgs::from_args(&args, 0)?;
|
||||||
let reduce_fn = FunctionParam {
|
let reduce_fn = FunctionParam {
|
||||||
inner: f.func,
|
inner: f.func,
|
||||||
@ -106,7 +106,7 @@ pub async fn array_reduce(exec_state: &mut ExecState, args: Args) -> Result<KclV
|
|||||||
ctx: args.ctx.clone(),
|
ctx: args.ctx.clone(),
|
||||||
memory: *f.memory,
|
memory: *f.memory,
|
||||||
};
|
};
|
||||||
inner_array_reduce(array, start, reduce_fn, exec_state, &args)
|
inner_reduce(array, start, reduce_fn, exec_state, &args)
|
||||||
.await
|
.await
|
||||||
.map(|sg| KclValue::UserVal(UserVal::new(sg.meta.clone(), sg)))
|
.map(|sg| KclValue::UserVal(UserVal::new(sg.meta.clone(), sg)))
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ pub async fn array_reduce(exec_state: &mut ExecState, args: Args) -> Result<KclV
|
|||||||
/// fn decagon = (radius) => {
|
/// fn decagon = (radius) => {
|
||||||
/// let step = (1/10) * tau()
|
/// let step = (1/10) * tau()
|
||||||
/// let sketch001 = startSketchAt([(cos(0)*radius), (sin(0) * radius)])
|
/// let sketch001 = startSketchAt([(cos(0)*radius), (sin(0) * radius)])
|
||||||
/// return arrayReduce([1..10], sketch001, (i, sg) => {
|
/// return reduce([1..10], sketch001, (i, sg) => {
|
||||||
/// let x = cos(step * i) * radius
|
/// let x = cos(step * i) * radius
|
||||||
/// let y = sin(step * i) * radius
|
/// let y = sin(step * i) * radius
|
||||||
/// return lineTo([x, y], sg)
|
/// return lineTo([x, y], sg)
|
||||||
@ -126,9 +126,9 @@ pub async fn array_reduce(exec_state: &mut ExecState, args: Args) -> Result<KclV
|
|||||||
/// decagon(5.0) |> close(%)
|
/// decagon(5.0) |> close(%)
|
||||||
/// ```
|
/// ```
|
||||||
#[stdlib {
|
#[stdlib {
|
||||||
name = "arrayReduce",
|
name = "reduce",
|
||||||
}]
|
}]
|
||||||
async fn inner_array_reduce<'a>(
|
async fn inner_reduce<'a>(
|
||||||
array: Vec<u64>,
|
array: Vec<u64>,
|
||||||
start: Sketch,
|
start: Sketch,
|
||||||
reduce_fn: FunctionParam<'a>,
|
reduce_fn: FunctionParam<'a>,
|
||||||
|
@ -97,7 +97,7 @@ lazy_static! {
|
|||||||
Box::new(crate::std::patterns::PatternCircular2D),
|
Box::new(crate::std::patterns::PatternCircular2D),
|
||||||
Box::new(crate::std::patterns::PatternCircular3D),
|
Box::new(crate::std::patterns::PatternCircular3D),
|
||||||
Box::new(crate::std::patterns::PatternTransform),
|
Box::new(crate::std::patterns::PatternTransform),
|
||||||
Box::new(crate::std::array::ArrayReduce),
|
Box::new(crate::std::array::Reduce),
|
||||||
Box::new(crate::std::array::Map),
|
Box::new(crate::std::array::Map),
|
||||||
Box::new(crate::std::chamfer::Chamfer),
|
Box::new(crate::std::chamfer::Chamfer),
|
||||||
Box::new(crate::std::fillet::Fillet),
|
Box::new(crate::std::fillet::Fillet),
|
||||||
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Reference in New Issue
Block a user