Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support mapEffect #298

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Lazy/fx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class FxAsyncIterable<A> {
return new FxAsyncIterable(map(f, this.asyncIterable));
}

/**
* A function that is identical to `map`, but is intended to create side effects as part of its convention.
*
* see {@link https://fxts.dev/docs/map | map}
*/
mapEffect<B>(f: (a: A) => B) {
return new FxAsyncIterable(map(f, this.asyncIterable));
}

/**
* Returns flattened AsyncIterable of values by running each element
* flattening the mapped results.
Expand Down Expand Up @@ -366,6 +375,15 @@ export class FxIterable<A> {
return new FxIterable(map(f, this.iterable));
}

/**
* A function that is identical to `map`, but is intended to create side effects as part of its convention.
*
* see {@link https://fxts.dev/docs/map | map}
*/
mapEffect<B>(f: (a: A) => B): FxIterable<B> {
return new FxIterable(map(f, this.iterable));
}

/**
* Returns flattened Iterable of values by running each element
* flattening the mapped results.
Expand Down
1 change: 1 addition & 0 deletions src/Lazy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export {
intersectionBy,
keys,
map,
map as mapEffect,
peek,
pipeLazy,
pluck,
Expand Down
5 changes: 3 additions & 2 deletions src/Lazy/map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AsyncFunctionException } from "../_internal/error";
import { isAsyncIterable, isIterable, isPromise } from "../_internal/utils";
import { isAsyncIterable, isIterable } from "../_internal/utils";
import type Awaited from "../types/Awaited";
import type IterableInfer from "../types/IterableInfer";
import type ReturnIterableIteratorType from "../types/ReturnIterableIteratorType";
Expand Down Expand Up @@ -55,6 +54,8 @@ function async<A, B>(
/**
* Returns Iterable/AsyncIterable of values by running each applying `f`.
*
* If the `map` causes side effects, it is recommended to use `mapEffect` instead.
*
* @example
* ```ts
* const iter = map(a => a + 10, [1, 2, 3, 4]);
Expand Down
4 changes: 3 additions & 1 deletion src/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ type HeadReturnType<T> = T extends readonly [a: infer H, ...rest: any[]]
: never;

/**
* Returns the first element of Iterable/AsyncIterable. (head)
* Returns the first element of Iterable/AsyncIterable.
*
* There is another alias function called `first`.
*
* @example
* ```ts
Expand Down
4 changes: 3 additions & 1 deletion src/includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import some from "./some";
import type ReturnValueType from "./types/ReturnValueType";

/**
* Checks if the specified value is equal. (contains)
* Checks if the specified value is equal.
*
* There is another alias function called `contains`.
*
* @example
* ```ts
Expand Down
Loading