ts-data-forge
Version:
[](https://www.npmjs.com/package/ts-data-forge) [](https://www.npmjs.com/package/ts-data-forge) [: PipeWithMapOptional<A>;
export declare function pipe<const A>(a: A): PipeBase<A>;
type Pipe<A> = A extends UnknownOptional ? PipeWithMapOptional<A> : PipeBase<A>;
/**
* @template A The type of the current value in the pipe.
* @internal
* Base pipe interface providing core functionality.
* All pipe types extend this interface.
*/
type PipeBase<A> = Readonly<{
/** The current value being piped. */
value: A;
/**
* Maps the current value to a new value using the provided function.
*
* @example
*
* ```ts
* const result = pipe(2)
* .map((value) => value * 3)
* .map((value) => `value: ${value}`);
*
* assert.deepStrictEqual(result.value, 'value: 6');
* ```
*
* @template B The type of the new value.
* @param fn Function to transform the current value.
* @returns A new pipe containing the transformed value.
*/
map: <B>(fn: (a: A) => B) => Pipe<B>;
/**
* Maps the current value only if it's not null or undefined. If the current
* value is null/undefined, the transformation is skipped and undefined is
* propagated through the pipe.
*
* @example
*
* ```ts
* const result = pipe<string | undefined>('hello')
* .mapNullable((value) => value.toUpperCase())
* .mapNullable((value) => value.slice(0, 2));
*
* assert.deepStrictEqual(result.value, 'HE');
*
* const empty = pipe<string | undefined>(undefined).mapNullable((value) =>
* value.toUpperCase(),
* );
*
* assert.isTrue(empty.value === undefined);
* ```
*
* @template B The type of the transformed value.
* @param fn Function to transform the non-null value.
* @returns A new pipe containing the transformed value or undefined.
*/
mapNullable: <B>(fn: (a: NonNullable<A>) => B) => Pipe<B | undefined>;
}>;
/**
* @template A The Optional type currently in the pipe.
* @internal
* Pipe interface for Optional values, providing Optional-aware mapping.
* Extends PipeBase with mapOptional functionality for monadic operations.
*/
type PipeWithMapOptional<A extends UnknownOptional> = MergeIntersection<PipeBase<A> & Readonly<{
/**
* Maps the value inside an Optional using Optional.map semantics. If the
* Optional is None, the transformation is skipped and None is propagated.
* If the Optional is Some, the transformation is applied to the inner
* value.
*
* @example
*
* ```ts
* const result = pipe(Optional.some(10))
* .mapOptional((value) => value * 2)
* .mapOptional((value) => value + 5);
*
* assert.deepStrictEqual(result.value, Optional.some(25));
*
* const empty = pipe(Optional.none as Optional<number>).mapOptional(
* (value) => value * 2,
* );
*
* assert.isTrue(Optional.isNone(empty.value));
* ```
*
* @template B The type of the transformed inner value.
* @param fn Function to transform the inner value of the Optional.
* @returns A new pipe containing an Optional with the transformed value.
*/
mapOptional: <B>(fn: (a: Optional.Unwrap<A>) => B) => Pipe<Optional<B>>;
}>>;
export {};
//# sourceMappingURL=pipe.d.mts.map