CKTIS / C
filtering and transformations — concept C23
Filtering retains elements that satisfy a predicate, while transformation produces a new value from each element; in C these are usually explicit loops or functions accepting a callback. Output size, in-place support, buffer overlap, and failure behavior must be part of the contract.
Version: C23
Syntax
filtering and transformationsFiltering retains elements that satisfy a predicate, while transformation produces a new value from each element; in C these are usually explicit loops or functions accepting a callback. Output size, in-place support, buffer overlap, and failure behavior must be part of the contract.
For in-place array filtering, keep separate read and write indices: copy every accepted element to write, then return the new length. Perform a transformation to another type in a separate buffer whose required size was checked first.
For an empty array, do not dereference the pointer; specify whether NULL with zero length is accepted. The predicate and transform must not invalidate the buffer or change its length during traversal, and a partial failure needs a defined output state.
Examples
#include <stdio.h>
int main(void) {
int values[] = {1, 2, 3, 4};
for (size_t i = 0; i < 4; ++i) if (values[i] > 2) printf("%d ", values[i] * 10);
putchar('\n');
return 0;
}
Result
30 40
Filtering retains elements that satisfy a predicate, while transformation produces a new value from each element; in C these are usually explicit loops or functions accepting a callback. Output size, in-place support, buffer overlap, and failure behavior must be part of the contract.