Skip to content

Commit

Permalink
feat: support mapEffect (#298)
Browse files Browse the repository at this point in the history
* feat: support mapEffect

* docs: update other alias function
  • Loading branch information
ppeeou authored Nov 26, 2024
1 parent 3c30c1e commit b98aa20
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
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

0 comments on commit b98aa20

Please sign in to comment.