Skip to content

fx-flow v0.7.0 / pipe/lazy / peek

Function: peek()

peek(fn, iterable)

peek<A>(fn, iterable): IterableIterator<A>

Call fn for each item in the iterable/asyncIterable and return the original iterable/asyncIterable.

Type parameters

A

Parameters

fn

iterable: Iterable<A>

Returns

IterableIterator<A>

Example

typescript
const iterator = peek(console.log, [1, 2, 3])

for (const v of iterator) {
  // log 1, 2, 3
  // v = 1, 2, 3
}

const iterator2 = peek(
  (v) => {
    v.a = 'b'
  },
  [{ a: 'a' }]
)

for (const v of iterator) {
  console.log(v) // log {a: 'b'}
}

More examples

Source

packages/core/src/pipe/lazy/peek.ts:32

peek(fn, iterable)

peek<A>(fn, iterable): AsyncIterableIterator<A>

Type parameters

A

Parameters

fn

iterable: AsyncIterable<A>

Returns

AsyncIterableIterator<A>

Source

packages/core/src/pipe/lazy/peek.ts:33

peek(fn)

peek<A>(fn): (iterable) => IteratorReturnValue<UniversalIterable<A>>

Type parameters

A

Parameters

fn

Returns

Function

Parameters

iterable: UniversalIterable<A>

Returns

IteratorReturnValue<UniversalIterable<A>>

Source

packages/core/src/pipe/lazy/peek.ts:34

Released under the MIT License.