1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 17:37:50 +01:00
amp/docs/iterators/transformation.md

21 lines
729 B
Markdown
Raw Normal View History

---
layout: docs
2017-05-26 21:13:34 +02:00
title: Iterator Transformation
permalink: /iterators/transformation
---
2019-10-11 20:30:42 +02:00
Amp provides some common transformation helpers for iterators: `map`, `filter` and `toArray`.
2019-10-11 20:30:42 +02:00
Further primitives are very easy to implement using `Producer` with these as examples.
## `map()`
`map()` accepts an `Iterator` and a `callable` `$onEmit` that can transform each value into another value.
## `filter()`
`filter()` accepts an `Iterator` and a `callable` `$filter`. If `$filter($value)` returns `false` the value gets filtered, otherwise the value is retained in the resulting `Iterator`.
2019-10-11 20:30:42 +02:00
## `toArray()`
`toArray()` accepts an `Iterator` and returns a `Promise` which resolves to an array of all the items from the iterator.