# each

```ts
function each<T>(source: Stream<T, unknown> | Subscription<T, unknown>): Operation<Iterable<T>>
```

Consume an Effection stream or subscription using a `for...of` loop.

Given any stream or subscription, you can access its values sequentially
using the `each()` operation, just as you would use a `for await...of` loop
with an async iterable:

### Examples
#### Example 1
```javascript
function* logValues(streamOrSubscription) {
  for (let value of yield* each(streamOrSubscription)) {
    console.log(value);
    yield* each.next();
  }
}
```

Pass an existing subscription when it must be active before iteration begins.

You must always invoke `each.next()` at the end of each iteration of the loop,
including if the iteration ends with a `continue` statement.

Note that just as with async iterators, there is no way to consume the
`TClose` value of a stream or subscription using the `for...of` loop.

---
### Type Parameters
T
the type of each value.


### Parameters


**source**: [Stream](https://frontside.com/effection/api/v4-next/Stream.md)&lt;T, unknown&gt; | [Subscription](https://frontside.com/effection/api/v4-next/Subscription.md)&lt;T, unknown&gt;


the stream or subscription to iterate
### Return Type


[Operation](https://frontside.com/effection/api/v4-next/Operation.md)&lt;Iterable&lt;T&gt;&gt;


an operation that iterates `source`

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/each.ts#L38)

```ts
namespace each
```

Additional properties on the `each` function.

[View code](https://github.com/thefrontside/effection/tree/effection-v4.2.0/lib/each.ts#L105)
