Skip to content

[RFC]: add ndarray/base/while-each #273

@kgryte

Description

@kgryte

This API is similar to ndarray/base/for-each, except that a provided function is only invoked while a predicate function returns true. Once the predicate function returns false, the function should immediately return.

API signature:

whileEach( arrays, predicate, fcn[, thisArg ] )

where

  • arrays: array-like object containing an input ndaray.
  • predicate: predicate function.
  • fcn: callback to apply.
  • thisArg: callback function execution context.

Both the predicate and callback functions should be provided the following arguments:

  • value: current array element.
  • indices: current array element indices.
  • arr: the input ndarray.

This package should be very similar to ndarray/base/for-each except that the inner loop logic becomes:

ind = take( [ i1, i0 ], idx );
if ( !predicate( xbuf[ ix ], ind, x.ref ) {
    return;
}
fcn.call( thisArg, xbuf[ ix ], ind, x.ref );
ix += dx0;

Metadata

Metadata

Assignees

Labels

FeatureTask to add a new feature.difficulty: 2May require some initial design or R&D, but should be straightforward to resolve and/or implement.estimate: 4-8hrsTask which should take between 4 to 8 hours.priority: NormalNormal priority concern or feature request.🤖 AIAllowed to use AI.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions