> For the complete documentation index, see [llms.txt](https://senselab.gitbook.io/senselab-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://senselab.gitbook.io/senselab-docs/vendor/sanmai/pipeline/docs/api/helpers.md).

# Helper Functions

Helper functions provide a convenient, fluent syntax for creating pipeline instances.

## `map()`

Creates a pipeline from a generator function or a single value.

**Signature**: `map(?callable $func = null): Standard`

* `$func`: An optional generator function.

**Behavior**:

* If `$func` is a generator, the pipeline is populated with the yielded values.
* If `$func` returns a single value, the pipeline will contain that one element.
* If no function is provided, an empty pipeline is created.

**Examples**:

```php
use function Pipeline\map;

// From a generator
$pipeline = map(function () {
    for ($i = 1; $i <= 3; $i++) {
        yield $i;
    }
});

// From a single value
$pipeline = map(fn() => 'Hello'); // Contains ['Hello']
```

## `take()`

Creates a pipeline from one or more iterables.

**Signature**: `take(?iterable $input = null, iterable ...$inputs): Standard`

* `$input`: The primary data source.
* `...$inputs`: Additional data sources to append.

**Examples**:

```php
use function Pipeline\take;

// From a single array
$pipeline = take([1, 2, 3]);

// From multiple sources
$pipeline = take([1, 2], new ArrayIterator([3, 4]));
```

## `fromArray()`

Creates a pipeline from an array, offering better type safety if you specifically need to handle an array.

**Signature**: `fromArray(array $input): Standard`

**Examples**:

```php
use function Pipeline\fromArray;

$pipeline = fromArray(['a' => 1, 'b' => 2]);
```

## `fromValues()`

Creates a pipeline from a sequence of individual values.

**Signature**: `fromValues(...$values): Standard`

**Examples**:

```php
use function Pipeline\fromValues;

$pipeline = fromValues(1, 'a', true);
```

## `zip()`

Combines multiple iterables into a single pipeline of tuples.

**Signature**: `zip(iterable $base, iterable ...$inputs): Standard`

**Behavior**:

* Creates a new pipeline where each element is an array of corresponding elements from the input iterables.
* Shorter iterables are padded with `null`.

**Examples**:

```php
use function Pipeline\zip;

$names = ['Alice', 'Bob'];
$ages = [30, 25];

$result = zip($names, $ages)->toList();
// [['Alice', 30], ['Bob', 25]]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://senselab.gitbook.io/senselab-docs/vendor/sanmai/pipeline/docs/api/helpers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
