# \*sequence()

[JS](https://lochiwei.gitbook.io/web/js) ⟩ [objects](https://lochiwei.gitbook.io/web/js/val/obj) ⟩ [built-in](https://lochiwei.gitbook.io/web/js/val/builtin) ⟩ [Generator](https://lochiwei.gitbook.io/web/js/iteration/generator) ⟩ [generator function](https://lochiwei.gitbook.io/web/js/iteration/generator/func) ⟩ [compostion](https://lochiwei.gitbook.io/web/js/iteration/generator/func/compose) ⟩ \*sequence()

{% hint style="success" %}
yield the values of [iterable](https://lochiwei.gitbook.io/web/js/iteration/iterable "mention")s <mark style="color:yellow;">**sequentially**</mark>.
{% endhint %}

{% tabs %}
{% tab title="📘 手冊" %}

* [yield\*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield*) [op](https://lochiwei.gitbook.io/web/js/grammar/op "mention") - can <mark style="color:red;">**only**</mark> be used <mark style="color:yellow;">**within**</mark> [func](https://lochiwei.gitbook.io/web/js/iteration/generator/func "mention")s❗️
  {% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="info" %} <mark style="color:blue;">**yield\***</mark> <mark style="color:yellow;">**keyword**</mark> iterates an [iterable](https://lochiwei.gitbook.io/web/js/iteration/iterable "mention") and yields each of the resulting values.
{% endhint %}

{% hint style="danger" %} <mark style="color:blue;">yield</mark> and [yield\*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield*) [op](https://lochiwei.gitbook.io/web/js/grammar/op "mention") can <mark style="color:red;">**only**</mark> be used <mark style="color:yellow;">**within**</mark> [func](https://lochiwei.gitbook.io/web/js/iteration/generator/func "mention")s❗️
{% endhint %}
{% endtab %}

{% tab title="💾 程式" %}

* replit：[sequence(...iterables)](https://replit.com/@pegasusroe/sequenceiterables#sequence.js)

```javascript
// ⭐ sequence()
//  yield the values of iterables sequentially
function* sequence(...iterables) {
    for (const iterable of iterables) {
        yield* iterable;
    }
}

// export
module.exports = sequence;
```

💈範例：

* require： [iterator](https://lochiwei.gitbook.io/web/js/iteration/iterator/iterator "mention"), [integers](https://lochiwei.gitbook.io/web/js/iteration/generator/examples/integers "mention")

```javascript
// ⭐ import
const Iterator = require('./Iterator.js');    // extend iterators
const integers = require('./integers.js');    // integers()
const sequence = require('./sequence.js');    // sequence()
// --------------------------------------------------------------

sequence(                 // iterables:
    integers().take(5),   //   • 0 ,  1 , 2, 3, 4
    "ab",                 //   • 'a', 'b'
    [0]                   //   • 0
).toArray()
// [ 0, 1, 2, 3, 4, 'a', 'b', 0]
```

{% endtab %}

{% tab title="👥 相關" %}

* [interleave](https://lochiwei.gitbook.io/web/js/iteration/generator/examples/interleave "mention") <mark style="color:yellow;">**interleaves**</mark> the values instead.
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] JavaScript: The Definitive Guide ⟩ 12.3 Generators
  {% endtab %}
  {% endtabs %}
