Skip to content
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
13 changes: 8 additions & 5 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ var Maybe = class _Maybe {
if (isNothing(this._value)) return new _Maybe(null);
const arr = this._value;
const result = [];
for (const el of arr) {
const maybeVal = fn(el);
for (let i = 0; i < arr.length; i++) {
const el = arr[i];
if (el === void 0) continue;
const maybeVal = fn(el, i);
if (!(maybeVal instanceof _Maybe)) return _Maybe.fromNullable(null);
if (isJust(maybeVal.value())) result.push(maybeVal.value());
const val = maybeVal.value();
if (isJust(val)) result.push(val);
}
return new _Maybe(result);
}
Expand Down Expand Up @@ -315,8 +318,8 @@ var AsyncMaybe = class _AsyncMaybe {
if (raw == null) return raw;
if (!Array.isArray(raw)) return null;
const values = await Promise.all(
raw.map(async (el) => {
const out = await fn(el);
raw.map(async (el, i) => {
const out = await fn(el, i);
if (out instanceof _AsyncMaybe) return await out.value();
if (out instanceof Maybe) return out.value();
return out;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ declare class AsyncMaybe<T> {
* @param fn - A function returning a Maybe/AsyncMaybe/value for each element.
* @returns A new AsyncMaybe containing the filtered/mapped array, or Nothing.
*/
filterMap<U, V>(this: AsyncMaybe<U[]>, fn: (value: U) => Maybe<V> | AsyncMaybe<V> | V | Promise<Maybe<V> | AsyncMaybe<V> | V>): AsyncMaybe<V[]>;
filterMap<U, V>(this: AsyncMaybe<U[]>, fn: (value: U, index: number) => Maybe<V> | AsyncMaybe<V> | V | Promise<Maybe<V> | AsyncMaybe<V> | V>): AsyncMaybe<V[]>;
first<Us extends ReadonlyArray<AsyncMaybe<unknown> | Maybe<unknown>>>(fn: (value: T) => Us): AsyncMaybe<ExtractMaybeArrayValue<Us>>;
/**
* withDefault - Provides a default value if Nothing.
Expand Down Expand Up @@ -265,7 +265,7 @@ declare class Maybe<T> {
* @param fn - A function mapping each element to a Maybe.
* @returns A Maybe of the filtered/mapped array, or Nothing if empty.
*/
filterMap<U, V>(this: Maybe<U[]>, fn: (value: U) => Maybe<V>): Maybe<V[]>;
filterMap<U, V>(this: Maybe<U[]>, fn: (value: U, index: number) => Maybe<V>): Maybe<V[]>;
/**
* Returns the first Maybe to produce a non-Nothing value
*
Expand Down Expand Up @@ -316,10 +316,10 @@ declare function filter<A>(predicate: (value: A) => boolean): {
(m: Maybe<A>): Maybe<A>;
(m: AsyncMaybe<A>): AsyncMaybe<A>;
};
declare function filterMap<A, B>(fn: (value: A) => Maybe<B>): {
declare function filterMap<A, B>(fn: (value: A, index: number) => Maybe<B>): {
<M extends Maybe<A[]> | AsyncMaybe<A[]>>(m: M): M extends AsyncMaybe<A[]> ? AsyncMaybe<B[]> : Maybe<B[]>;
};
declare function filterMap<A, B>(fn: (value: A) => AsyncMaybe<B>): {
declare function filterMap<A, B>(fn: (value: A, index: number) => AsyncMaybe<B>): {
(m: Maybe<A[]>): AsyncMaybe<B[]>;
(m: AsyncMaybe<A[]>): AsyncMaybe<B[]>;
};
Expand Down
8 changes: 4 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ declare class AsyncMaybe<T> {
* @param fn - A function returning a Maybe/AsyncMaybe/value for each element.
* @returns A new AsyncMaybe containing the filtered/mapped array, or Nothing.
*/
filterMap<U, V>(this: AsyncMaybe<U[]>, fn: (value: U) => Maybe<V> | AsyncMaybe<V> | V | Promise<Maybe<V> | AsyncMaybe<V> | V>): AsyncMaybe<V[]>;
filterMap<U, V>(this: AsyncMaybe<U[]>, fn: (value: U, index: number) => Maybe<V> | AsyncMaybe<V> | V | Promise<Maybe<V> | AsyncMaybe<V> | V>): AsyncMaybe<V[]>;
first<Us extends ReadonlyArray<AsyncMaybe<unknown> | Maybe<unknown>>>(fn: (value: T) => Us): AsyncMaybe<ExtractMaybeArrayValue<Us>>;
/**
* withDefault - Provides a default value if Nothing.
Expand Down Expand Up @@ -265,7 +265,7 @@ declare class Maybe<T> {
* @param fn - A function mapping each element to a Maybe.
* @returns A Maybe of the filtered/mapped array, or Nothing if empty.
*/
filterMap<U, V>(this: Maybe<U[]>, fn: (value: U) => Maybe<V>): Maybe<V[]>;
filterMap<U, V>(this: Maybe<U[]>, fn: (value: U, index: number) => Maybe<V>): Maybe<V[]>;
/**
* Returns the first Maybe to produce a non-Nothing value
*
Expand Down Expand Up @@ -316,10 +316,10 @@ declare function filter<A>(predicate: (value: A) => boolean): {
(m: Maybe<A>): Maybe<A>;
(m: AsyncMaybe<A>): AsyncMaybe<A>;
};
declare function filterMap<A, B>(fn: (value: A) => Maybe<B>): {
declare function filterMap<A, B>(fn: (value: A, index: number) => Maybe<B>): {
<M extends Maybe<A[]> | AsyncMaybe<A[]>>(m: M): M extends AsyncMaybe<A[]> ? AsyncMaybe<B[]> : Maybe<B[]>;
};
declare function filterMap<A, B>(fn: (value: A) => AsyncMaybe<B>): {
declare function filterMap<A, B>(fn: (value: A, index: number) => AsyncMaybe<B>): {
(m: Maybe<A[]>): AsyncMaybe<B[]>;
(m: AsyncMaybe<A[]>): AsyncMaybe<B[]>;
};
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading