Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
iter.c File Reference

Iterator-style helpers exposed as built-ins (enumerate, zip). More...

#include "value.h"
#include <stdlib.h>
Include dependency graph for iter.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Value bi_enumerate (const Value *arr)
 Build an array of [index, value] pairs from an input array.
Value bi_zip (const Value *a, const Value *b)
 Zip two arrays into an array of pairs up to the shorter length.

Detailed Description

Iterator-style helpers exposed as built-ins (enumerate, zip).

Definition in file iter.c.

Function Documentation

◆ bi_enumerate()

Value bi_enumerate(const Value *arr)

Build an array of [index, value] pairs from an input array.

For an input array [v0, v1, ...], returns [[0, v0], [1, v1], ...]. Non-array inputs are treated as empty arrays by array_length/array_get_copy.

Ownership: The returned Value owns its internal array; caller must free it with free_value().

Parameters
arrInput array Value.
Returns
An array Value of length equal to the input's length.

Definition at line 30 of file iter.c.

Here is the call graph for this function:

◆ bi_zip()

Value bi_zip(const Value *a,
const Value *b )

Zip two arrays into an array of pairs up to the shorter length.

For inputs a=[a0,a1,...], b=[b0,b1,...], returns [[a0,b0],[a1,b1], ...] with length min(len(a), len(b)).

Ownership: The returned Value owns its internal array; caller must free it with free_value().

Parameters
aFirst input array Value.
bSecond input array Value.
Returns
Array of pairs as a Value.

Definition at line 66 of file iter.c.

Here is the call graph for this function: