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:
Adam Chalmers
2024-09-30 20:03:28 -05:00
committed by GitHub
parent a3c0a2b03b
commit 258bce8adc
8 changed files with 3916 additions and 3916 deletions

File diff suppressed because one or more lines are too long

View File

@ -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

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -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]]

View File

@ -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>,

View File

@ -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),

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB