Skip to content

Function: fromAny()

fromAny<R>(value): Stream<R>

Defined in: converters/fromAny.ts:21

Converts a wide variety of input values into a Stream.

This function normalizes different asynchronous or synchronous sources into a unified Stream<R> so they can be processed uniformly in operators and pipelines.

Supported inputs:

  • A <R> (returned as-is).
  • A <R> (a value or a promise resolving to a value), wrapped into a single–emission stream.
  • An array of R, converted into a stream using from.

Type Parameters

R

R = any

The type of values emitted by the resulting stream.

Parameters

value

The input source to convert into a stream. Can be a stream, a value, a promise, or an array of values.

Stream<R> | CallbackReturnType<R> | R[]

Returns

Stream<R>

A <R> representing the given input.

Examples

From fromAny.spec.ts:4

typescript
const originalStream = createStream('test', async function* () {
  yield 42;
});
const result = fromAny(originalStream);
expect(result).toBe(originalStream);
const values: number[] = [];
result.subscribe({
  next: (v) => values.push(v),
  complete: () => {
    expect(values).toEqual([42]);
    done();
  },
});

Released under the MIT License.