@depup/remeda 2.45.0-depup.0 → 2.48.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,8 +13,8 @@ npm install @depup/remeda
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [remeda](https://www.npmjs.com/package/remeda) @ 2.45.0 |
17
- | Processed | 2026-08-30 |
16
+ | Original | [remeda](https://www.npmjs.com/package/remeda) @ 2.48.0 |
17
+ | Processed | 2026-09-13 |
18
18
  | Smoke test | passed |
19
19
  | Deps updated | 0 |
20
20
 
package/changes.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "bumped": {},
3
- "timestamp": "2026-08-30T00:58:50.625Z",
3
+ "timestamp": "2026-09-13T00:58:58.520Z",
4
4
  "totalUpdated": 0
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"endsWith.cjs","names":["purry"],"sources":["../src/endsWith.ts"],"sourcesContent":["/* eslint-disable unicorn/consistent-boolean-name --\n * When we mirror a built-in function we use the same name for it.\n */\n\nimport { purry } from \"./purry\";\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(data, suffix);\n * @example\n * endsWith(\"hello world\", \"hello\"); // false\n * endsWith(\"hello world\", \"world\"); // true\n * @dataFirst\n * @category String\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n suffix: string extends Suffix ? never : Suffix,\n): data is T & `${string}${Suffix}`;\nexport function endsWith(data: string, suffix: string): boolean;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(suffix)(data);\n * @example\n * pipe(\"hello world\", endsWith(\"hello\")); // false\n * pipe(\"hello world\", endsWith(\"world\")); // true\n * @dataLast\n * @category String\n */\nexport function endsWith<Suffix extends string>(\n suffix: string extends Suffix ? never : Suffix,\n): <T extends string>(data: T) => data is T & `${string}${Suffix}`;\nexport function endsWith(suffix: string): (data: string) => boolean;\n\nexport function endsWith(...args: readonly unknown[]): unknown {\n return purry(endsWithImplementation, args);\n}\n\nconst endsWithImplementation = (data: string, suffix: string): boolean =>\n data.endsWith(suffix);\n"],"mappings":"kGAoDA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAOA,EAAAA,MAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GAA0B,EAAc,IAC5C,EAAK,SAAS,CAAM"}
1
+ {"version":3,"file":"endsWith.cjs","names":["purry"],"sources":["../src/endsWith.ts"],"sourcesContent":["/* eslint-disable unicorn/consistent-boolean-name --\n * When we mirror a built-in function we use the same name for it.\n */\n\nimport type {\n IsEqual,\n IsNever,\n IsStringLiteral,\n UnionToIntersection,\n} from \"type-fest\";\nimport type { Boxed } from \"./internal/types/Boxed\";\nimport { purry } from \"./purry\";\n\n// By intersecting with a suffix template we force all types that satisfy this\n// type to also be of this shape. For a raw primitive string this narrows\n// exactly to the suffix template, for a literal TypeScript checks if it\n// satisfies the condition and narrow to `never` if not (and distribute the\n// check for unions). The only limitation is for unbounded template literals, as\n// TypeScript leaves the intersection as-is, even when they are disjoint.\ntype EndsWith<T, Suffix extends string> = T & `${string}${Suffix}`;\n\n// The same intersection, but requiring *every* possible runtime value of the\n// suffix instead of any of them. Only one of them is the suffix at runtime, and\n// which one is unknowable, so a failed check can only rule out values that\n// would have matched no matter which one it was.\ntype EndsWithEvery<T, Suffix extends string> = T &\n // 4. And then we intersect the suffixes instead of adding them to a union to\n // flip the semantics from \"OR\" to \"AND\", so that the resulting suffix\n // limitation is the tightest possible combination of all suffixes, and not\n // the widest one, before unwrapping the box.\n Boxed.Extract<\n UnionToIntersection<\n // 1. We first distribute the union to compute the suffix for each member\n // of the union separately (otherwise the suffix itself would contain\n // the union).\n Suffix extends unknown\n ? // 3. Each suffix is boxed so that it survives as a distinct union\n // member until the intersection. Unboxed, a `never` would vanish from\n // the union instead of emptying the intersection, and an empty\n // suffix's `string` would absorb its siblings via subtype reduction.\n Boxed<\n // 2. Unbounded template strings represent infinite possible\n // suffixes, which is exactly the kind of uncertainty that we are\n // working to resolve here, only literals are workable here.\n IsStringLiteral<Suffix> extends true ? `${string}${Suffix}` : never\n >\n : never\n >\n >;\n\n// TypeScript treats type-guards as complementary (e.g., everything either\n// fully satisfies the type, or fully doesn't, typing the falsy branch similar\n// to the result of `Exclude<T, Condition>`). `endsWith` doesn't have this\n// relationship when `Suffix` is a union because we don't **know** which of the\n// union members match, so we can't narrow the falsy branch at all. The only way\n// to prevent this is to prevent TypeScript from using the narrowing overload\n// in cases where we know the narrowing wouldn't be sound.\ntype IsNarrowingUnsound<T, Suffix extends string> = IsEqual<\n // We simulate the falsy branch using the actual narrowing type we use and\n // the type created by narrowing via *all* union members together.\n IsEqual<\n Exclude<T, EndsWith<T, Suffix>>,\n Exclude<T, EndsWithEvery<T, Suffix>>\n >,\n // We want to find the cases where they don't agree, this means that narrowing\n // would result in an unsound overly-narrow falsy branch.\n false\n>;\n\n/**\n * **IMPORTANT**: When a literal suffix doesn't match *any* of the possible\n * values of `data` the call itself is rejected by disabling its return type.\n * If this overload signature was chosen for your call most likely your suffix\n * has a typo or `data` itself has changed and it no longer satisfies the\n * `suffix`.\n *\n * If you still need to make the check on these values widen one of them to\n * `string`.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @example\n * endsWith(\"cat\" as (\"cat\" | \"dog\"), \"bird\"); //=> void\n * endsWith(\"cat\" as (\"cat\" | \"dog\"), \"bird\" as string); //=> boolean\n * @hidden\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n // This signature has to come first so that TypeScript would pick it only\n // when it would result in narrowing to `never`; by returning void the\n // signature effectively \"disables\" the usefulness of the function, in most\n // cases surfacing a compile-time error, allowing users to detect typos or\n // dead code at the call site itself instead of relying on downstream errors.\n // @see https://github.com/remeda/remeda/issues/1432\n suffix: IsNever<EndsWith<T, Suffix>> extends true ? Suffix : never,\n): void;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * Suffixes that `data` can never end with are rejected at compile-time.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(data, suffix);\n * @example\n * endsWith(\"hello world\", \"world\"); //=> true\n * endsWith(\"hello world\" as string, \"hello\"); //=> false\n * @dataFirst\n * @category String\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n // Reject primitive strings, they can't be used to narrow T. They would match\n // the non-narrowing overload.\n suffix: string extends Suffix\n ? never\n : // Union suffixes are rejected too when the guard they'd produce isn't\n // sound.\n IsNarrowingUnsound<T, Suffix> extends true\n ? never\n : Suffix,\n): data is EndsWith<T, Suffix>;\n\nexport function endsWith(data: string, suffix: string): boolean;\n\n/**\n * **IMPORTANT**: When a literal suffix doesn't match *any* of the possible\n * values of `data` the call itself is rejected by disabling its return type.\n * If this overload signature was chosen for your call most likely your suffix\n * has a typo or `data` itself has changed and it no longer satisfies the\n * `suffix`.\n *\n * If you still need to make the check on these values widen one of them to\n * `string`.\n *\n * @param suffix - The string to check for at the end.\n * @example\n * pipe(\"cat\" as (\"cat\" | \"dog\"), endsWith(\"bird\")); //=> void\n * pipe(\"cat\" as (\"cat\" | \"dog\"), endsWith(\"bird\" as string)); //=> boolean\n * @hidden\n */\nexport function endsWith<T extends string, Suffix extends string>(\n // This signature has to come first so that TypeScript would pick it only\n // when it would result in narrowing to `never`; by returning void the\n // signature effectively \"disables\" the usefulness of the function, in most\n // cases surfacing a compile-time error, allowing users to detect typos or\n // dead code at the call site itself instead of relying on downstream errors.\n // @see https://github.com/remeda/remeda/issues/1432\n suffix: IsNever<EndsWith<T, Suffix>> extends true ? Suffix : never,\n): (data: T) => void;\n\nexport function endsWith<T extends string, Suffix extends string>(\n // In the narrowing data-last overload we move the type of `data` to the\n // returned callback so that it could defer the inference to the wrapper,\n // allowing it to support complex compositions (e.g., `isNot`); but our\n // soundness check requires the `data` type so it could compare against it.\n // To work around this we need an additional overload that would only match\n // the unsound cases. If the inputs are sound, it wouldn't match and allow us\n // to fall through to the next overload.\n suffix: IsNarrowingUnsound<T, Suffix> extends true ? Suffix : never,\n): (data: T) => boolean;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * Suffixes that `data` can never end with are rejected at compile-time.\n *\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(suffix)(data);\n * @example\n * pipe(\"hello world\", endsWith(\"world\")); //=> true\n * pipe(\"hello world\", endsWith(\"hello\")); //=> false\n * @dataLast\n * @category String\n */\nexport function endsWith<Suffix extends string>(\n // Reject primitive strings, they can't be used to narrow T. They would match\n // the non-narrowing overload.\n suffix: string extends Suffix ? never : Suffix,\n): <T extends string>(data: T) => data is EndsWith<T, Suffix>;\n\nexport function endsWith(suffix: string): (data: string) => boolean;\n\nexport function endsWith(...args: readonly unknown[]): unknown {\n return purry(endsWithImplementation, args);\n}\n\nconst endsWithImplementation = (data: string, suffix: string): boolean =>\n data.endsWith(suffix);\n"],"mappings":"kGAoMA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAOA,EAAAA,MAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GAA0B,EAAc,IAC5C,EAAK,SAAS,CAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"endsWith.js","names":[],"sources":["../src/endsWith.ts"],"sourcesContent":["/* eslint-disable unicorn/consistent-boolean-name --\n * When we mirror a built-in function we use the same name for it.\n */\n\nimport { purry } from \"./purry\";\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(data, suffix);\n * @example\n * endsWith(\"hello world\", \"hello\"); // false\n * endsWith(\"hello world\", \"world\"); // true\n * @dataFirst\n * @category String\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n suffix: string extends Suffix ? never : Suffix,\n): data is T & `${string}${Suffix}`;\nexport function endsWith(data: string, suffix: string): boolean;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(suffix)(data);\n * @example\n * pipe(\"hello world\", endsWith(\"hello\")); // false\n * pipe(\"hello world\", endsWith(\"world\")); // true\n * @dataLast\n * @category String\n */\nexport function endsWith<Suffix extends string>(\n suffix: string extends Suffix ? never : Suffix,\n): <T extends string>(data: T) => data is T & `${string}${Suffix}`;\nexport function endsWith(suffix: string): (data: string) => boolean;\n\nexport function endsWith(...args: readonly unknown[]): unknown {\n return purry(endsWithImplementation, args);\n}\n\nconst endsWithImplementation = (data: string, suffix: string): boolean =>\n data.endsWith(suffix);\n"],"mappings":"mCAoDA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAO,EAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GAA0B,EAAc,IAC5C,EAAK,SAAS,CAAM"}
1
+ {"version":3,"file":"endsWith.js","names":[],"sources":["../src/endsWith.ts"],"sourcesContent":["/* eslint-disable unicorn/consistent-boolean-name --\n * When we mirror a built-in function we use the same name for it.\n */\n\nimport type {\n IsEqual,\n IsNever,\n IsStringLiteral,\n UnionToIntersection,\n} from \"type-fest\";\nimport type { Boxed } from \"./internal/types/Boxed\";\nimport { purry } from \"./purry\";\n\n// By intersecting with a suffix template we force all types that satisfy this\n// type to also be of this shape. For a raw primitive string this narrows\n// exactly to the suffix template, for a literal TypeScript checks if it\n// satisfies the condition and narrow to `never` if not (and distribute the\n// check for unions). The only limitation is for unbounded template literals, as\n// TypeScript leaves the intersection as-is, even when they are disjoint.\ntype EndsWith<T, Suffix extends string> = T & `${string}${Suffix}`;\n\n// The same intersection, but requiring *every* possible runtime value of the\n// suffix instead of any of them. Only one of them is the suffix at runtime, and\n// which one is unknowable, so a failed check can only rule out values that\n// would have matched no matter which one it was.\ntype EndsWithEvery<T, Suffix extends string> = T &\n // 4. And then we intersect the suffixes instead of adding them to a union to\n // flip the semantics from \"OR\" to \"AND\", so that the resulting suffix\n // limitation is the tightest possible combination of all suffixes, and not\n // the widest one, before unwrapping the box.\n Boxed.Extract<\n UnionToIntersection<\n // 1. We first distribute the union to compute the suffix for each member\n // of the union separately (otherwise the suffix itself would contain\n // the union).\n Suffix extends unknown\n ? // 3. Each suffix is boxed so that it survives as a distinct union\n // member until the intersection. Unboxed, a `never` would vanish from\n // the union instead of emptying the intersection, and an empty\n // suffix's `string` would absorb its siblings via subtype reduction.\n Boxed<\n // 2. Unbounded template strings represent infinite possible\n // suffixes, which is exactly the kind of uncertainty that we are\n // working to resolve here, only literals are workable here.\n IsStringLiteral<Suffix> extends true ? `${string}${Suffix}` : never\n >\n : never\n >\n >;\n\n// TypeScript treats type-guards as complementary (e.g., everything either\n// fully satisfies the type, or fully doesn't, typing the falsy branch similar\n// to the result of `Exclude<T, Condition>`). `endsWith` doesn't have this\n// relationship when `Suffix` is a union because we don't **know** which of the\n// union members match, so we can't narrow the falsy branch at all. The only way\n// to prevent this is to prevent TypeScript from using the narrowing overload\n// in cases where we know the narrowing wouldn't be sound.\ntype IsNarrowingUnsound<T, Suffix extends string> = IsEqual<\n // We simulate the falsy branch using the actual narrowing type we use and\n // the type created by narrowing via *all* union members together.\n IsEqual<\n Exclude<T, EndsWith<T, Suffix>>,\n Exclude<T, EndsWithEvery<T, Suffix>>\n >,\n // We want to find the cases where they don't agree, this means that narrowing\n // would result in an unsound overly-narrow falsy branch.\n false\n>;\n\n/**\n * **IMPORTANT**: When a literal suffix doesn't match *any* of the possible\n * values of `data` the call itself is rejected by disabling its return type.\n * If this overload signature was chosen for your call most likely your suffix\n * has a typo or `data` itself has changed and it no longer satisfies the\n * `suffix`.\n *\n * If you still need to make the check on these values widen one of them to\n * `string`.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @example\n * endsWith(\"cat\" as (\"cat\" | \"dog\"), \"bird\"); //=> void\n * endsWith(\"cat\" as (\"cat\" | \"dog\"), \"bird\" as string); //=> boolean\n * @hidden\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n // This signature has to come first so that TypeScript would pick it only\n // when it would result in narrowing to `never`; by returning void the\n // signature effectively \"disables\" the usefulness of the function, in most\n // cases surfacing a compile-time error, allowing users to detect typos or\n // dead code at the call site itself instead of relying on downstream errors.\n // @see https://github.com/remeda/remeda/issues/1432\n suffix: IsNever<EndsWith<T, Suffix>> extends true ? Suffix : never,\n): void;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * Suffixes that `data` can never end with are rejected at compile-time.\n *\n * @param data - The input string.\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(data, suffix);\n * @example\n * endsWith(\"hello world\", \"world\"); //=> true\n * endsWith(\"hello world\" as string, \"hello\"); //=> false\n * @dataFirst\n * @category String\n */\nexport function endsWith<T extends string, Suffix extends string>(\n data: T,\n // Reject primitive strings, they can't be used to narrow T. They would match\n // the non-narrowing overload.\n suffix: string extends Suffix\n ? never\n : // Union suffixes are rejected too when the guard they'd produce isn't\n // sound.\n IsNarrowingUnsound<T, Suffix> extends true\n ? never\n : Suffix,\n): data is EndsWith<T, Suffix>;\n\nexport function endsWith(data: string, suffix: string): boolean;\n\n/**\n * **IMPORTANT**: When a literal suffix doesn't match *any* of the possible\n * values of `data` the call itself is rejected by disabling its return type.\n * If this overload signature was chosen for your call most likely your suffix\n * has a typo or `data` itself has changed and it no longer satisfies the\n * `suffix`.\n *\n * If you still need to make the check on these values widen one of them to\n * `string`.\n *\n * @param suffix - The string to check for at the end.\n * @example\n * pipe(\"cat\" as (\"cat\" | \"dog\"), endsWith(\"bird\")); //=> void\n * pipe(\"cat\" as (\"cat\" | \"dog\"), endsWith(\"bird\" as string)); //=> boolean\n * @hidden\n */\nexport function endsWith<T extends string, Suffix extends string>(\n // This signature has to come first so that TypeScript would pick it only\n // when it would result in narrowing to `never`; by returning void the\n // signature effectively \"disables\" the usefulness of the function, in most\n // cases surfacing a compile-time error, allowing users to detect typos or\n // dead code at the call site itself instead of relying on downstream errors.\n // @see https://github.com/remeda/remeda/issues/1432\n suffix: IsNever<EndsWith<T, Suffix>> extends true ? Suffix : never,\n): (data: T) => void;\n\nexport function endsWith<T extends string, Suffix extends string>(\n // In the narrowing data-last overload we move the type of `data` to the\n // returned callback so that it could defer the inference to the wrapper,\n // allowing it to support complex compositions (e.g., `isNot`); but our\n // soundness check requires the `data` type so it could compare against it.\n // To work around this we need an additional overload that would only match\n // the unsound cases. If the inputs are sound, it wouldn't match and allow us\n // to fall through to the next overload.\n suffix: IsNarrowingUnsound<T, Suffix> extends true ? Suffix : never,\n): (data: T) => boolean;\n\n/**\n * Determines whether a string ends with the provided suffix, and refines the\n * output type if possible.\n *\n * This function is a wrapper around the built-in [`String.prototype.endsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)\n * method, but doesn't expose the `endPosition` parameter. To check only up to a\n * specific position, use `endsWith(sliceString(data, 0, endPosition), suffix)`.\n *\n * Suffixes that `data` can never end with are rejected at compile-time.\n *\n * @param suffix - The string to check for at the end.\n * @signature\n * endsWith(suffix)(data);\n * @example\n * pipe(\"hello world\", endsWith(\"world\")); //=> true\n * pipe(\"hello world\", endsWith(\"hello\")); //=> false\n * @dataLast\n * @category String\n */\nexport function endsWith<Suffix extends string>(\n // Reject primitive strings, they can't be used to narrow T. They would match\n // the non-narrowing overload.\n suffix: string extends Suffix ? never : Suffix,\n): <T extends string>(data: T) => data is EndsWith<T, Suffix>;\n\nexport function endsWith(suffix: string): (data: string) => boolean;\n\nexport function endsWith(...args: readonly unknown[]): unknown {\n return purry(endsWithImplementation, args);\n}\n\nconst endsWithImplementation = (data: string, suffix: string): boolean =>\n data.endsWith(suffix);\n"],"mappings":"mCAoMA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAO,EAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GAA0B,EAAc,IAC5C,EAAK,SAAS,CAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"filter.cjs","names":["purry","SKIP_ITEM"],"sources":["../src/filter.ts"],"sourcesContent":["import type { Writable } from \"type-fest\";\nimport type { FilteredArray } from \"./internal/types/FilteredArray\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\n// When the predicate used for filter isn't refining (like a type-predicate) we\n// can narrow the result slightly if it's also trivial (it returns the same\n// result for all items). This is uncommon, but can be useful to \"short-circuit\"\n// the filter.\ntype NonRefinedFilteredArray<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n> = boolean extends IsItemIncluded\n ? // We don't know which items of the array the predicate would allow in the\n // output so we can only safely say that the result is an array with items\n // from the input array.\n // TODO: Theoretically we could build an output shape that would take into account the **order** of elements in the input array by reconstructing it with every single element in it either included or not, but this type can grow to a union of as much as 2^n options which might not be usable in practice.\n T[number][]\n : IsItemIncluded extends true\n ? // If the predicate is always true we return a shallow copy of the array.\n // If it was originally readonly we need to strip that away.\n Writable<T>\n : // If the predicate is always false we will always return an empty\n // array.\n [];\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param data - The array to filter.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(data, predicate)\n * @example\n * filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): FilteredArray<T, Condition>;\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): NonRefinedFilteredArray<T, IsItemIncluded>;\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(predicate)(data)\n * @example\n * pipe([1, 2, 3], filter(x => x % 2 === 1)) // => [1, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): (data: T) => FilteredArray<T, Condition>;\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): (data: T) => NonRefinedFilteredArray<T, IsItemIncluded>;\n\nexport function filter(...args: readonly unknown[]): unknown {\n return purry(filterImplementation, args, lazyImplementation);\n}\n\nconst filterImplementation = <T>(\n data: readonly T[],\n predicate: (value: T, index: number, array: readonly T[]) => boolean,\n): T[] => data.filter(predicate);\n\nconst lazyImplementation =\n <T>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n ): LazyEvaluator<T> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: false, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"gJA6FA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAOA,EAAAA,MAAM,EAAsB,EAAM,CAAkB,CAC7D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,OAAO,CAAS,EAEzB,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM,EAC1CC,EAAAA"}
1
+ {"version":3,"file":"filter.cjs","names":["purry","SKIP_ITEM"],"sources":["../src/filter.ts"],"sourcesContent":["import type { FilteredArray } from \"./internal/types/FilteredArray\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type {\n LazyCallback,\n LazyTypePredicate,\n} from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport type { NonRefinedFilteredArray } from \"./internal/types/NonRefinedFilteredArray\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param data - The array to filter.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(data, predicate)\n * @example\n * filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): FilteredArray<T, Condition>;\n\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): NonRefinedFilteredArray<T, IsItemIncluded>;\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(predicate)(data)\n * @example\n * pipe([1, 2, 3], filter(x => x % 2 === 1)) // => [1, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n predicate: LazyTypePredicate<T, Condition>,\n): (data: T) => FilteredArray<T, Condition>;\n\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: LazyCallback<T, IsItemIncluded>,\n): (data: T) => NonRefinedFilteredArray<T, IsItemIncluded>;\n\nexport function filter(...args: readonly unknown[]): unknown {\n return purry(filterImplementation, args, lazyImplementation);\n}\n\nconst filterImplementation = <T>(\n data: readonly T[],\n predicate: (value: T, index: number, array: readonly T[]) => boolean,\n): T[] => data.filter(predicate);\n\nconst lazyImplementation =\n <T>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n ): LazyEvaluator<T> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: false, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"gJA8EA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAOA,EAAAA,MAAM,EAAsB,EAAM,CAAkB,CAC7D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,OAAO,CAAS,EAEzB,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM,EAC1CC,EAAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"filter.js","names":[],"sources":["../src/filter.ts"],"sourcesContent":["import type { Writable } from \"type-fest\";\nimport type { FilteredArray } from \"./internal/types/FilteredArray\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\n// When the predicate used for filter isn't refining (like a type-predicate) we\n// can narrow the result slightly if it's also trivial (it returns the same\n// result for all items). This is uncommon, but can be useful to \"short-circuit\"\n// the filter.\ntype NonRefinedFilteredArray<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n> = boolean extends IsItemIncluded\n ? // We don't know which items of the array the predicate would allow in the\n // output so we can only safely say that the result is an array with items\n // from the input array.\n // TODO: Theoretically we could build an output shape that would take into account the **order** of elements in the input array by reconstructing it with every single element in it either included or not, but this type can grow to a union of as much as 2^n options which might not be usable in practice.\n T[number][]\n : IsItemIncluded extends true\n ? // If the predicate is always true we return a shallow copy of the array.\n // If it was originally readonly we need to strip that away.\n Writable<T>\n : // If the predicate is always false we will always return an empty\n // array.\n [];\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param data - The array to filter.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(data, predicate)\n * @example\n * filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): FilteredArray<T, Condition>;\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): NonRefinedFilteredArray<T, IsItemIncluded>;\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(predicate)(data)\n * @example\n * pipe([1, 2, 3], filter(x => x % 2 === 1)) // => [1, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): (data: T) => FilteredArray<T, Condition>;\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): (data: T) => NonRefinedFilteredArray<T, IsItemIncluded>;\n\nexport function filter(...args: readonly unknown[]): unknown {\n return purry(filterImplementation, args, lazyImplementation);\n}\n\nconst filterImplementation = <T>(\n data: readonly T[],\n predicate: (value: T, index: number, array: readonly T[]) => boolean,\n): T[] => data.filter(predicate);\n\nconst lazyImplementation =\n <T>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n ): LazyEvaluator<T> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: false, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"kFA6FA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAO,EAAM,EAAsB,EAAM,CAAkB,CAC7D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,OAAO,CAAS,EAEzB,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM,EAC1C"}
1
+ {"version":3,"file":"filter.js","names":[],"sources":["../src/filter.ts"],"sourcesContent":["import type { FilteredArray } from \"./internal/types/FilteredArray\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type {\n LazyCallback,\n LazyTypePredicate,\n} from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport type { NonRefinedFilteredArray } from \"./internal/types/NonRefinedFilteredArray\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param data - The array to filter.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(data, predicate)\n * @example\n * filter([1, 2, 3], x => x % 2 === 1) // => [1, 3]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): FilteredArray<T, Condition>;\n\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): NonRefinedFilteredArray<T, IsItemIncluded>;\n\n/**\n * Creates a shallow copy of a portion of a given array, filtered down to just\n * the elements from the given array that pass the test implemented by the\n * provided function. Equivalent to `Array.prototype.filter`.\n *\n * Related operations:\n * - `splice` - to shape the array by *position* rather than by *value*.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to keep the element in the resulting array, and `false`\n * otherwise. A type-predicate can also be used to narrow the result.\n * @returns A shallow copy of the given array containing just the elements that\n * pass the test. If no elements pass the test, an empty array is returned.\n * @signature\n * filter(predicate)(data)\n * @example\n * pipe([1, 2, 3], filter(x => x % 2 === 1)) // => [1, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function filter<T extends IterableContainer, Condition>(\n predicate: LazyTypePredicate<T, Condition>,\n): (data: T) => FilteredArray<T, Condition>;\n\nexport function filter<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: LazyCallback<T, IsItemIncluded>,\n): (data: T) => NonRefinedFilteredArray<T, IsItemIncluded>;\n\nexport function filter(...args: readonly unknown[]): unknown {\n return purry(filterImplementation, args, lazyImplementation);\n}\n\nconst filterImplementation = <T>(\n data: readonly T[],\n predicate: (value: T, index: number, array: readonly T[]) => boolean,\n): T[] => data.filter(predicate);\n\nconst lazyImplementation =\n <T>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n ): LazyEvaluator<T> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: false, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"kFA8EA,SAAgB,EAAO,GAAG,EAAmC,CAC3D,OAAO,EAAM,EAAsB,EAAM,CAAkB,CAC7D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,OAAO,CAAS,EAEzB,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM,EAC1C"}
package/dist/find.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"find.cjs","names":["purry","toSingle","SKIP_ITEM"],"sources":["../src/find.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(data, predicate)\n * @example\n * find([1, 3, 4, 6], n => n % 2 === 0) // => 4\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function find<T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined;\nexport function find<T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): T | undefined;\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * find(n => n % 2 === 0)\n * ) // => 4\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function find<T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): (data: readonly T[]) => S | undefined;\nexport function find<T>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): (data: readonly T[]) => T | undefined;\n\nexport function find(...args: readonly unknown[]): unknown {\n return purry(findImplementation, args, toSingle(lazyImplementation));\n}\n\nconst findImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => data.find(predicate);\n\nconst lazyImplementation =\n <T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n ): LazyEvaluator<T, S> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: true, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"qLA6EA,SAAgB,EAAK,GAAG,EAAmC,CACzD,OAAOA,EAAAA,MAAM,EAAoB,EAAMC,EAAAA,EAAS,CAAkB,CAAC,CACrE,CAEA,MAAM,GACJ,EACA,IACkB,EAAK,KAAK,CAAS,EAEjC,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAM,QAAS,GAAM,KAAM,CAAM,EACzCC,EAAAA"}
1
+ {"version":3,"file":"find.cjs","names":["purry","toSingle","SKIP_ITEM"],"sources":["../src/find.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { Assignability } from \"./internal/types/Assignability\";\nimport type { First } from \"./internal/types/First\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type {\n LazyCallback,\n LazyTypePredicate,\n} from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport type { Narrowed } from \"./internal/types/Narrowed\";\nimport type { TupleParts } from \"./internal/types/TupleParts\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\ntype Found<T extends IterableContainer, Condition> =\n // We distribute the array type to support unions of arrays/tuples.\n T extends unknown\n ? FoundInFixedTuple<\n TupleParts<T>[\"required\"],\n Condition,\n // When the required part doesn't have any item that would always match\n // we fall back to the optional parts of the tuple which might match.\n | Narrowed<TupleParts<T>[\"optional\"][number], Condition>\n | Narrowed<TupleParts<T>[\"item\"], Condition>\n // A non-trivial suffix part can only show up if a non-trivial optional\n // part or a non-trivial item exists, so it is always part of the\n // fallback of the required part.\n | FoundInFixedTuple<\n TupleParts<T>[\"suffix\"],\n Condition,\n // When an item isn't found we need to return `undefined`, but\n // because it might still always exist in the suffix we set this\n // return value as the fallback of the suffix part, this way if the\n // suffix has a match the fallback isn't reached and we don't add\n // the `undefined`, and in any other case the fallback would make\n // sure we cover this case too.\n undefined\n >\n >\n : never;\n\n// This type only works under the assumption that T is a simple fixed tuple (no\n// optional items and no rest items)!\ntype FoundInFixedTuple<T, Condition, Fallback> = T extends readonly [\n infer Head,\n ...infer Rest,\n]\n ? Assignability<\n Head,\n Condition,\n {\n full: Head;\n\n // Because the match isn't full we need to also consider the rest of the\n // items too because in runtime we might skip the current item.\n partial:\n | Narrowed<Head, Condition>\n | FoundInFixedTuple<Rest, Condition, Fallback>;\n none: FoundInFixedTuple<Rest, Condition, Fallback>;\n }\n >\n : Fallback;\n\n// For non-type-narrowing predicates, we can only provide more refined type when\n// we know the predicate returns a constant literal boolean value.\ntype FoundNonRefined<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n> = boolean extends IsItemIncluded\n ? T[number] | undefined\n : IsItemIncluded extends true\n ? // `find(data, constant(true))` is equivalent to `first(data)`.\n First<T>\n : undefined;\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(data, predicate)\n * @example\n * find([1, 3, 4, 6], n => n % 2 === 0) // => 4\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function find<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): Found<T, Condition>;\n\nexport function find<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): FoundNonRefined<T, IsItemIncluded>;\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * find(n => n % 2 === 0)\n * ) // => 4\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function find<T extends IterableContainer, Condition>(\n predicate: LazyTypePredicate<T, Condition>,\n): (data: T) => Found<T, Condition>;\n\nexport function find<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: LazyCallback<T, IsItemIncluded>,\n): (data: T) => FoundNonRefined<T, IsItemIncluded>;\n\nexport function find(...args: readonly unknown[]): unknown {\n return purry(findImplementation, args, toSingle(lazyImplementation));\n}\n\nconst findImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => data.find(predicate);\n\nconst lazyImplementation =\n <T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n ): LazyEvaluator<T, S> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: true, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"qLA2JA,SAAgB,EAAK,GAAG,EAAmC,CACzD,OAAOA,EAAAA,MAAM,EAAoB,EAAMC,EAAAA,EAAS,CAAkB,CAAC,CACrE,CAEA,MAAM,GACJ,EACA,IACkB,EAAK,KAAK,CAAS,EAEjC,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAM,QAAS,GAAM,KAAM,CAAM,EACzCC,EAAAA"}
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"find.js","names":[],"sources":["../src/find.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(data, predicate)\n * @example\n * find([1, 3, 4, 6], n => n % 2 === 0) // => 4\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function find<T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined;\nexport function find<T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): T | undefined;\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * find(n => n % 2 === 0)\n * ) // => 4\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function find<T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): (data: readonly T[]) => S | undefined;\nexport function find<T>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): (data: readonly T[]) => T | undefined;\n\nexport function find(...args: readonly unknown[]): unknown {\n return purry(findImplementation, args, toSingle(lazyImplementation));\n}\n\nconst findImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => data.find(predicate);\n\nconst lazyImplementation =\n <T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n ): LazyEvaluator<T, S> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: true, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"6HA6EA,SAAgB,EAAK,GAAG,EAAmC,CACzD,OAAO,EAAM,EAAoB,EAAM,EAAS,CAAkB,CAAC,CACrE,CAEA,MAAM,GACJ,EACA,IACkB,EAAK,KAAK,CAAS,EAEjC,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAM,QAAS,GAAM,KAAM,CAAM,EACzC"}
1
+ {"version":3,"file":"find.js","names":[],"sources":["../src/find.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { Assignability } from \"./internal/types/Assignability\";\nimport type { First } from \"./internal/types/First\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type {\n LazyCallback,\n LazyTypePredicate,\n} from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport type { Narrowed } from \"./internal/types/Narrowed\";\nimport type { TupleParts } from \"./internal/types/TupleParts\";\nimport { SKIP_ITEM } from \"./internal/utilityEvaluators\";\nimport { purry } from \"./purry\";\n\ntype Found<T extends IterableContainer, Condition> =\n // We distribute the array type to support unions of arrays/tuples.\n T extends unknown\n ? FoundInFixedTuple<\n TupleParts<T>[\"required\"],\n Condition,\n // When the required part doesn't have any item that would always match\n // we fall back to the optional parts of the tuple which might match.\n | Narrowed<TupleParts<T>[\"optional\"][number], Condition>\n | Narrowed<TupleParts<T>[\"item\"], Condition>\n // A non-trivial suffix part can only show up if a non-trivial optional\n // part or a non-trivial item exists, so it is always part of the\n // fallback of the required part.\n | FoundInFixedTuple<\n TupleParts<T>[\"suffix\"],\n Condition,\n // When an item isn't found we need to return `undefined`, but\n // because it might still always exist in the suffix we set this\n // return value as the fallback of the suffix part, this way if the\n // suffix has a match the fallback isn't reached and we don't add\n // the `undefined`, and in any other case the fallback would make\n // sure we cover this case too.\n undefined\n >\n >\n : never;\n\n// This type only works under the assumption that T is a simple fixed tuple (no\n// optional items and no rest items)!\ntype FoundInFixedTuple<T, Condition, Fallback> = T extends readonly [\n infer Head,\n ...infer Rest,\n]\n ? Assignability<\n Head,\n Condition,\n {\n full: Head;\n\n // Because the match isn't full we need to also consider the rest of the\n // items too because in runtime we might skip the current item.\n partial:\n | Narrowed<Head, Condition>\n | FoundInFixedTuple<Rest, Condition, Fallback>;\n none: FoundInFixedTuple<Rest, Condition, Fallback>;\n }\n >\n : Fallback;\n\n// For non-type-narrowing predicates, we can only provide more refined type when\n// we know the predicate returns a constant literal boolean value.\ntype FoundNonRefined<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n> = boolean extends IsItemIncluded\n ? T[number] | undefined\n : IsItemIncluded extends true\n ? // `find(data, constant(true))` is equivalent to `first(data)`.\n First<T>\n : undefined;\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(data, predicate)\n * @example\n * find([1, 3, 4, 6], n => n % 2 === 0) // => 4\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function find<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): Found<T, Condition>;\n\nexport function find<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): FoundNonRefined<T, IsItemIncluded>;\n\n/**\n * Returns the first element in the provided array that satisfies the provided\n * testing function. If no values satisfy the testing function, `undefined` is\n * returned.\n *\n * Similar functions:\n * * `findLast` - If you need the last element that satisfies the provided testing function.\n * * `findIndex` - If you need the index of the found element in the array.\n * * `indexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The first element in the array that satisfies the provided testing\n * function. Otherwise, `undefined` is returned.\n * @signature\n * find(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * find(n => n % 2 === 0)\n * ) // => 4\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function find<T extends IterableContainer, Condition>(\n predicate: LazyTypePredicate<T, Condition>,\n): (data: T) => Found<T, Condition>;\n\nexport function find<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: LazyCallback<T, IsItemIncluded>,\n): (data: T) => FoundNonRefined<T, IsItemIncluded>;\n\nexport function find(...args: readonly unknown[]): unknown {\n return purry(findImplementation, args, toSingle(lazyImplementation));\n}\n\nconst findImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => data.find(predicate);\n\nconst lazyImplementation =\n <T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n ): LazyEvaluator<T, S> =>\n (value, index, data) =>\n predicate(value, index, data)\n ? { done: true, hasNext: true, next: value }\n : SKIP_ITEM;\n"],"mappings":"6HA2JA,SAAgB,EAAK,GAAG,EAAmC,CACzD,OAAO,EAAM,EAAoB,EAAM,EAAS,CAAkB,CAAC,CACrE,CAEA,MAAM,GACJ,EACA,IACkB,EAAK,KAAK,CAAS,EAEjC,EAEF,IAED,EAAO,EAAO,IACb,EAAU,EAAO,EAAO,CAAI,EACxB,CAAE,KAAM,GAAM,QAAS,GAAM,KAAM,CAAM,EACzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findLast.cjs","names":["purry"],"sources":["../src/findLast.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(data, predicate)\n * @example\n * findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3\n * @dataFirst\n * @category Array\n */\nexport function findLast<T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined;\nexport function findLast<T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): T | undefined;\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * findLast(n => n % 2 === 1)\n * ) // => 3\n * @dataLast\n * @category Array\n */\nexport function findLast<T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): (data: readonly T[]) => S | undefined;\nexport function findLast<T = never>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): (data: readonly T[]) => T | undefined;\n\nexport function findLast(...args: readonly unknown[]): unknown {\n return purry(findLastImplementation, args);\n}\n\nconst findLastImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => {\n // TODO [>2]: When node 18 reaches end-of-life bump target lib to ES2023+ and use `Array.prototype.findLast` here.\n\n for (let i = data.length - 1; i >= 0; i--) {\n const item = data[i]!;\n if (predicate(item, i, data)) {\n return item;\n }\n }\n\n return undefined;\n};\n"],"mappings":"kGAwEA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAOA,EAAAA,MAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GACJ,EACA,IACkB,CAGlB,IAAK,IAAI,EAAI,EAAK,OAAS,EAAG,GAAK,EAAG,IAAK,CACzC,IAAM,EAAO,EAAK,GAClB,GAAI,EAAU,EAAM,EAAG,CAAI,EACzB,OAAO,CAEX,CAGF"}
1
+ {"version":3,"file":"findLast.cjs","names":["purry"],"sources":["../src/findLast.ts"],"sourcesContent":["import type { LastArrayElement } from \"type-fest\";\nimport type { Assignability } from \"./internal/types/Assignability\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { Narrowed } from \"./internal/types/Narrowed\";\nimport type { TupleParts } from \"./internal/types/TupleParts\";\nimport { purry } from \"./purry\";\n\ntype FoundLast<T extends IterableContainer, Condition> =\n // We distribute the array type to support unions of arrays/tuples.\n T extends unknown\n ? FoundLastInFixedTuple<\n TupleParts<T>[\"suffix\"],\n Condition,\n // When the suffix part doesn't have any item that would always match\n // we fall back to the optional parts of the tuple which might match.\n | Narrowed<TupleParts<T>[\"item\"], Condition>\n | Narrowed<TupleParts<T>[\"optional\"][number], Condition>\n // The required part is always present, but it precedes every other\n // part of the tuple, so any match in it is only the last one when the\n // parts after it have none; this makes it the fallback of them all.\n | FoundLastInFixedTuple<\n TupleParts<T>[\"required\"],\n Condition,\n // When an item isn't found we need to return `undefined`, but\n // because it might still always exist in the required part we set\n // this return value as the fallback of the required part, this way\n // if the required part has a match the fallback isn't reached and\n // we don't add the `undefined`, and in any other case the fallback\n // would make sure we cover this case too.\n undefined\n >\n >\n : never;\n\n// This type only works under the assumption that T is a simple fixed tuple (no\n// optional items and no rest items)!\ntype FoundLastInFixedTuple<T, Condition, Fallback> = T extends readonly [\n ...infer Rest,\n infer Last,\n]\n ? Assignability<\n Last,\n Condition,\n {\n full: Last;\n\n // Because the match isn't full we need to also consider the rest of the\n // items too because in runtime we might skip the current item.\n partial:\n | Narrowed<Last, Condition>\n | FoundLastInFixedTuple<Rest, Condition, Fallback>;\n none: FoundLastInFixedTuple<Rest, Condition, Fallback>;\n }\n >\n : Fallback;\n\n// For non-type-narrowing predicates, we can only provide more refined type when\n// we know the predicate returns a constant literal boolean value.\ntype FoundLastNonRefined<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n> = boolean extends IsItemIncluded\n ? T[number] | undefined\n : IsItemIncluded extends true\n ? // `findLast(data, constant(true))` is equivalent to `last(data)`.\n LastArrayElement<T>\n : undefined;\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(data, predicate)\n * @example\n * findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3\n * @dataFirst\n * @category Array\n */\nexport function findLast<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): FoundLast<T, Condition>;\n\nexport function findLast<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): FoundLastNonRefined<T, IsItemIncluded>;\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * findLast(n => n % 2 === 1)\n * ) // => 3\n * @dataLast\n * @category Array\n */\nexport function findLast<T extends IterableContainer, Condition>(\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): (data: T) => FoundLast<T, Condition>;\n\nexport function findLast<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): (data: T) => FoundLastNonRefined<T, IsItemIncluded>;\n\nexport function findLast(...args: readonly unknown[]): unknown {\n return purry(findLastImplementation, args);\n}\n\nconst findLastImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => {\n // TODO [>2]: When node 18 reaches end-of-life bump target lib to ES2023+ and use `Array.prototype.findLast` here.\n\n for (let i = data.length - 1; i >= 0; i--) {\n const item = data[i]!;\n if (predicate(item, i, data)) {\n return item;\n }\n }\n\n return undefined;\n};\n"],"mappings":"kGAkJA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAOA,EAAAA,MAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GACJ,EACA,IACkB,CAGlB,IAAK,IAAI,EAAI,EAAK,OAAS,EAAG,GAAK,EAAG,IAAK,CACzC,IAAM,EAAO,EAAK,GAClB,GAAI,EAAU,EAAM,EAAG,CAAI,EACzB,OAAO,CAEX,CAGF"}
@@ -1 +1 @@
1
- {"version":3,"file":"findLast.js","names":[],"sources":["../src/findLast.ts"],"sourcesContent":["import { purry } from \"./purry\";\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(data, predicate)\n * @example\n * findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3\n * @dataFirst\n * @category Array\n */\nexport function findLast<T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined;\nexport function findLast<T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): T | undefined;\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * findLast(n => n % 2 === 1)\n * ) // => 3\n * @dataLast\n * @category Array\n */\nexport function findLast<T, S extends T>(\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): (data: readonly T[]) => S | undefined;\nexport function findLast<T = never>(\n predicate: (value: T, index: number, data: readonly T[]) => boolean,\n): (data: readonly T[]) => T | undefined;\n\nexport function findLast(...args: readonly unknown[]): unknown {\n return purry(findLastImplementation, args);\n}\n\nconst findLastImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => {\n // TODO [>2]: When node 18 reaches end-of-life bump target lib to ES2023+ and use `Array.prototype.findLast` here.\n\n for (let i = data.length - 1; i >= 0; i--) {\n const item = data[i]!;\n if (predicate(item, i, data)) {\n return item;\n }\n }\n\n return undefined;\n};\n"],"mappings":"mCAwEA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAO,EAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GACJ,EACA,IACkB,CAGlB,IAAK,IAAI,EAAI,EAAK,OAAS,EAAG,GAAK,EAAG,IAAK,CACzC,IAAM,EAAO,EAAK,GAClB,GAAI,EAAU,EAAM,EAAG,CAAI,EACzB,OAAO,CAEX,CAGF"}
1
+ {"version":3,"file":"findLast.js","names":[],"sources":["../src/findLast.ts"],"sourcesContent":["import type { LastArrayElement } from \"type-fest\";\nimport type { Assignability } from \"./internal/types/Assignability\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { Narrowed } from \"./internal/types/Narrowed\";\nimport type { TupleParts } from \"./internal/types/TupleParts\";\nimport { purry } from \"./purry\";\n\ntype FoundLast<T extends IterableContainer, Condition> =\n // We distribute the array type to support unions of arrays/tuples.\n T extends unknown\n ? FoundLastInFixedTuple<\n TupleParts<T>[\"suffix\"],\n Condition,\n // When the suffix part doesn't have any item that would always match\n // we fall back to the optional parts of the tuple which might match.\n | Narrowed<TupleParts<T>[\"item\"], Condition>\n | Narrowed<TupleParts<T>[\"optional\"][number], Condition>\n // The required part is always present, but it precedes every other\n // part of the tuple, so any match in it is only the last one when the\n // parts after it have none; this makes it the fallback of them all.\n | FoundLastInFixedTuple<\n TupleParts<T>[\"required\"],\n Condition,\n // When an item isn't found we need to return `undefined`, but\n // because it might still always exist in the required part we set\n // this return value as the fallback of the required part, this way\n // if the required part has a match the fallback isn't reached and\n // we don't add the `undefined`, and in any other case the fallback\n // would make sure we cover this case too.\n undefined\n >\n >\n : never;\n\n// This type only works under the assumption that T is a simple fixed tuple (no\n// optional items and no rest items)!\ntype FoundLastInFixedTuple<T, Condition, Fallback> = T extends readonly [\n ...infer Rest,\n infer Last,\n]\n ? Assignability<\n Last,\n Condition,\n {\n full: Last;\n\n // Because the match isn't full we need to also consider the rest of the\n // items too because in runtime we might skip the current item.\n partial:\n | Narrowed<Last, Condition>\n | FoundLastInFixedTuple<Rest, Condition, Fallback>;\n none: FoundLastInFixedTuple<Rest, Condition, Fallback>;\n }\n >\n : Fallback;\n\n// For non-type-narrowing predicates, we can only provide more refined type when\n// we know the predicate returns a constant literal boolean value.\ntype FoundLastNonRefined<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n> = boolean extends IsItemIncluded\n ? T[number] | undefined\n : IsItemIncluded extends true\n ? // `findLast(data, constant(true))` is equivalent to `last(data)`.\n LastArrayElement<T>\n : undefined;\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param data - The items to search in.\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(data, predicate)\n * @example\n * findLast([1, 3, 4, 6], n => n % 2 === 1) // => 3\n * @dataFirst\n * @category Array\n */\nexport function findLast<T extends IterableContainer, Condition>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): FoundLast<T, Condition>;\n\nexport function findLast<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n data: T,\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): FoundLastNonRefined<T, IsItemIncluded>;\n\n/**\n * Iterates the array in reverse order and returns the value of the first\n * element that satisfies the provided testing function. If no elements satisfy\n * the testing function, undefined is returned.\n *\n * Similar functions:\n * * `find` - If you need the first element that satisfies the provided testing function.\n * * `findLastIndex` - If you need the index of the found element in the array.\n * * `lastIndexOf` - If you need to find the index of a value.\n * * `includes` - If you need to find if a value exists in an array.\n * * `some` - If you need to find if any element satisfies the provided testing function.\n * * `filter` - If you need to find all elements that satisfy the provided testing function.\n *\n * @param predicate - A function to execute for each element in the array. It\n * should return `true` to indicate a matching element has been found, and\n * `false` otherwise. A type-predicate can also be used to narrow the result.\n * @returns The last (highest-index) element in the array that satisfies the\n * provided testing function; undefined if no matching element is found.\n * @signature\n * findLast(predicate)(data)\n * @example\n * pipe(\n * [1, 3, 4, 6],\n * findLast(n => n % 2 === 1)\n * ) // => 3\n * @dataLast\n * @category Array\n */\nexport function findLast<T extends IterableContainer, Condition>(\n predicate: (value: T[number], index: number, data: T) => value is Condition,\n): (data: T) => FoundLast<T, Condition>;\n\nexport function findLast<\n T extends IterableContainer,\n IsItemIncluded extends boolean,\n>(\n predicate: (value: T[number], index: number, data: T) => IsItemIncluded,\n): (data: T) => FoundLastNonRefined<T, IsItemIncluded>;\n\nexport function findLast(...args: readonly unknown[]): unknown {\n return purry(findLastImplementation, args);\n}\n\nconst findLastImplementation = <T, S extends T>(\n data: readonly T[],\n predicate: (value: T, index: number, data: readonly T[]) => value is S,\n): S | undefined => {\n // TODO [>2]: When node 18 reaches end-of-life bump target lib to ES2023+ and use `Array.prototype.findLast` here.\n\n for (let i = data.length - 1; i >= 0; i--) {\n const item = data[i]!;\n if (predicate(item, i, data)) {\n return item;\n }\n }\n\n return undefined;\n};\n"],"mappings":"mCAkJA,SAAgB,EAAS,GAAG,EAAmC,CAC7D,OAAO,EAAM,EAAwB,CAAI,CAC3C,CAEA,MAAM,GACJ,EACA,IACkB,CAGlB,IAAK,IAAI,EAAI,EAAK,OAAS,EAAG,GAAK,EAAG,IAAK,CACzC,IAAM,EAAO,EAAK,GAClB,GAAI,EAAU,EAAM,EAAG,CAAI,EACzB,OAAO,CAEX,CAGF"}
@@ -1 +1 @@
1
- {"version":3,"file":"first.cjs","names":["purry","toSingle"],"sources":["../src/first.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\ntype First<T extends IterableContainer> = T extends []\n ? undefined\n : T extends readonly [unknown, ...unknown[]]\n ? T[0]\n : T extends readonly [...infer Pre, infer Last]\n ? Last | Pre[0]\n : T[0] | undefined;\n\n/**\n * Gets the first element of `array`.\n *\n * @param data - The array.\n * @returns The first element of the array.\n * @signature\n * first(array)\n * @example\n * first([1, 2, 3]) // => 1\n * first([]) // => undefined\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function first<T extends IterableContainer>(data: T): First<T>;\n\n/**\n * Gets the first element of `array`.\n *\n * @returns The first element of the array.\n * @signature\n * first()(array)\n * @example\n * pipe(\n * [1, 2, 4, 8, 16],\n * filter(x => x > 3),\n * first(),\n * x => x + 1\n * ); // => 5\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function first(): <T extends IterableContainer>(data: T) => First<T>;\n\nexport function first(...args: readonly unknown[]): unknown {\n return purry(firstImplementation, args, toSingle(lazyImplementation));\n}\n\nconst firstImplementation = <T>([item]: readonly T[]): T | undefined => item;\n\nconst lazyImplementation = (): LazyEvaluator => firstLazy;\n\nconst firstLazy = <T>(value: T) =>\n ({ hasNext: true, next: value, done: true }) as const;\n"],"mappings":"uIAgDA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAOA,EAAAA,MAAM,EAAqB,EAAMC,EAAAA,EAAS,CAAkB,CAAC,CACtE,CAEA,MAAM,GAA0B,CAAC,KAAuC,EAElE,MAA0C,EAE1C,EAAgB,IACnB,CAAE,QAAS,GAAM,KAAM,EAAO,KAAM,EAAK"}
1
+ {"version":3,"file":"first.cjs","names":["purry","toSingle"],"sources":["../src/first.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { First } from \"./internal/types/First\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Gets the first element of `array`.\n *\n * @param data - The array.\n * @returns The first element of the array.\n * @signature\n * first(array)\n * @example\n * first([1, 2, 3]) // => 1\n * first([]) // => undefined\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function first<T extends IterableContainer>(data: T): First<T>;\n\n/**\n * Gets the first element of `array`.\n *\n * @returns The first element of the array.\n * @signature\n * first()(array)\n * @example\n * pipe(\n * [1, 2, 4, 8, 16],\n * filter(x => x > 3),\n * first(),\n * x => x + 1\n * ); // => 5\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function first(): <T extends IterableContainer>(data: T) => First<T>;\n\nexport function first(...args: readonly unknown[]): unknown {\n return purry(firstImplementation, args, toSingle(lazyImplementation));\n}\n\nconst firstImplementation = <T>([item]: readonly T[]): T | undefined => item;\n\nconst lazyImplementation = (): LazyEvaluator => firstLazy;\n\nconst firstLazy = <T>(value: T) =>\n ({ hasNext: true, next: value, done: true }) as const;\n"],"mappings":"uIAyCA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAOA,EAAAA,MAAM,EAAqB,EAAMC,EAAAA,EAAS,CAAkB,CAAC,CACtE,CAEA,MAAM,GAA0B,CAAC,KAAuC,EAElE,MAA0C,EAE1C,EAAgB,IACnB,CAAE,QAAS,GAAM,KAAM,EAAO,KAAM,EAAK"}
package/dist/first.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"first.js","names":[],"sources":["../src/first.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\ntype First<T extends IterableContainer> = T extends []\n ? undefined\n : T extends readonly [unknown, ...unknown[]]\n ? T[0]\n : T extends readonly [...infer Pre, infer Last]\n ? Last | Pre[0]\n : T[0] | undefined;\n\n/**\n * Gets the first element of `array`.\n *\n * @param data - The array.\n * @returns The first element of the array.\n * @signature\n * first(array)\n * @example\n * first([1, 2, 3]) // => 1\n * first([]) // => undefined\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function first<T extends IterableContainer>(data: T): First<T>;\n\n/**\n * Gets the first element of `array`.\n *\n * @returns The first element of the array.\n * @signature\n * first()(array)\n * @example\n * pipe(\n * [1, 2, 4, 8, 16],\n * filter(x => x > 3),\n * first(),\n * x => x + 1\n * ); // => 5\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function first(): <T extends IterableContainer>(data: T) => First<T>;\n\nexport function first(...args: readonly unknown[]): unknown {\n return purry(firstImplementation, args, toSingle(lazyImplementation));\n}\n\nconst firstImplementation = <T>([item]: readonly T[]): T | undefined => item;\n\nconst lazyImplementation = (): LazyEvaluator => firstLazy;\n\nconst firstLazy = <T>(value: T) =>\n ({ hasNext: true, next: value, done: true }) as const;\n"],"mappings":"yEAgDA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAO,EAAM,EAAqB,EAAM,EAAS,CAAkB,CAAC,CACtE,CAEA,MAAM,GAA0B,CAAC,KAAuC,EAElE,MAA0C,EAE1C,EAAgB,IACnB,CAAE,QAAS,GAAM,KAAM,EAAO,KAAM,EAAK"}
1
+ {"version":3,"file":"first.js","names":[],"sources":["../src/first.ts"],"sourcesContent":["import { toSingle } from \"./internal/toSingle\";\nimport type { First } from \"./internal/types/First\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Gets the first element of `array`.\n *\n * @param data - The array.\n * @returns The first element of the array.\n * @signature\n * first(array)\n * @example\n * first([1, 2, 3]) // => 1\n * first([]) // => undefined\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function first<T extends IterableContainer>(data: T): First<T>;\n\n/**\n * Gets the first element of `array`.\n *\n * @returns The first element of the array.\n * @signature\n * first()(array)\n * @example\n * pipe(\n * [1, 2, 4, 8, 16],\n * filter(x => x > 3),\n * first(),\n * x => x + 1\n * ); // => 5\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function first(): <T extends IterableContainer>(data: T) => First<T>;\n\nexport function first(...args: readonly unknown[]): unknown {\n return purry(firstImplementation, args, toSingle(lazyImplementation));\n}\n\nconst firstImplementation = <T>([item]: readonly T[]): T | undefined => item;\n\nconst lazyImplementation = (): LazyEvaluator => firstLazy;\n\nconst firstLazy = <T>(value: T) =>\n ({ hasNext: true, next: value, done: true }) as const;\n"],"mappings":"yEAyCA,SAAgB,EAAM,GAAG,EAAmC,CAC1D,OAAO,EAAM,EAAqB,EAAM,EAAS,CAAkB,CAAC,CACtE,CAEA,MAAM,GAA0B,CAAC,KAAuC,EAElE,MAA0C,EAE1C,EAAgB,IACnB,CAAE,QAAS,GAAM,KAAM,EAAO,KAAM,EAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"flatMap.cjs","names":["purry"],"sources":["../src/flatMap.ts"],"sourcesContent":["import type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param data - The items to map and flatten.\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(data, callbackfn)\n * @example\n * flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n data: readonly T[],\n callbackfn: (input: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[];\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(callbackfn)(data)\n * @example\n * pipe([1, 2, 3], flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n callbackfn: (input: T, index: number, data: readonly T[]) => readonly U[] | U,\n): (data: readonly T[]) => U[];\n\nexport function flatMap(...args: readonly unknown[]): unknown {\n return purry(flatMapImplementation, args, lazyImplementation);\n}\n\nconst flatMapImplementation = <T, U>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[] => data.flatMap(callbackfn);\n\nconst lazyImplementation =\n <T, K>(\n callbackfn: (\n input: T,\n index: number,\n data: readonly T[],\n ) => K | readonly K[],\n ): LazyEvaluator<T, K> =>\n // @ts-expect-error [ts2322] - We need to make LazyMany better so it accommodate the typing here...\n (value, index, data) => {\n const next = callbackfn(value, index, data);\n return Array.isArray(next)\n ? { done: false, hasNext: true, hasMany: true, next }\n : { done: false, hasNext: true, next };\n };\n"],"mappings":"kGAqDA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAOA,EAAAA,MAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,QAAQ,CAAU,EAE3B,EAEF,IAOD,EAAO,EAAO,IAAS,CACtB,IAAM,EAAO,EAAW,EAAO,EAAO,CAAI,EAC1C,OAAO,MAAM,QAAQ,CAAI,EACrB,CAAE,KAAM,GAAO,QAAS,GAAM,QAAS,GAAM,MAAK,EAClD,CAAE,KAAM,GAAO,QAAS,GAAM,MAAK,CACzC"}
1
+ {"version":3,"file":"flatMap.cjs","names":["purry"],"sources":["../src/flatMap.ts"],"sourcesContent":["import type { LazyCallback } from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param data - The items to map and flatten.\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(data, callbackfn)\n * @example\n * flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n data: readonly T[],\n callbackfn: (input: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[];\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(callbackfn)(data)\n * @example\n * pipe([1, 2, 3], flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n callbackfn: LazyCallback<readonly T[], readonly U[] | U>,\n): (data: readonly T[]) => U[];\n\nexport function flatMap(...args: readonly unknown[]): unknown {\n return purry(flatMapImplementation, args, lazyImplementation);\n}\n\nconst flatMapImplementation = <T, U>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[] => data.flatMap(callbackfn);\n\nconst lazyImplementation =\n <T, K>(\n callbackfn: (\n input: T,\n index: number,\n data: readonly T[],\n ) => K | readonly K[],\n ): LazyEvaluator<T, K> =>\n // @ts-expect-error [ts2322] - We need to make LazyMany better so it accommodate the typing here...\n (value, index, data) => {\n const next = callbackfn(value, index, data);\n return Array.isArray(next)\n ? { done: false, hasNext: true, hasMany: true, next }\n : { done: false, hasNext: true, next };\n };\n"],"mappings":"kGAsDA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAOA,EAAAA,MAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,QAAQ,CAAU,EAE3B,EAEF,IAOD,EAAO,EAAO,IAAS,CACtB,IAAM,EAAO,EAAW,EAAO,EAAO,CAAI,EAC1C,OAAO,MAAM,QAAQ,CAAI,EACrB,CAAE,KAAM,GAAO,QAAS,GAAM,QAAS,GAAM,MAAK,EAClD,CAAE,KAAM,GAAO,QAAS,GAAM,MAAK,CACzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"flatMap.js","names":[],"sources":["../src/flatMap.ts"],"sourcesContent":["import type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param data - The items to map and flatten.\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(data, callbackfn)\n * @example\n * flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n data: readonly T[],\n callbackfn: (input: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[];\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(callbackfn)(data)\n * @example\n * pipe([1, 2, 3], flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n callbackfn: (input: T, index: number, data: readonly T[]) => readonly U[] | U,\n): (data: readonly T[]) => U[];\n\nexport function flatMap(...args: readonly unknown[]): unknown {\n return purry(flatMapImplementation, args, lazyImplementation);\n}\n\nconst flatMapImplementation = <T, U>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[] => data.flatMap(callbackfn);\n\nconst lazyImplementation =\n <T, K>(\n callbackfn: (\n input: T,\n index: number,\n data: readonly T[],\n ) => K | readonly K[],\n ): LazyEvaluator<T, K> =>\n // @ts-expect-error [ts2322] - We need to make LazyMany better so it accommodate the typing here...\n (value, index, data) => {\n const next = callbackfn(value, index, data);\n return Array.isArray(next)\n ? { done: false, hasNext: true, hasMany: true, next }\n : { done: false, hasNext: true, next };\n };\n"],"mappings":"mCAqDA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAO,EAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,QAAQ,CAAU,EAE3B,EAEF,IAOD,EAAO,EAAO,IAAS,CACtB,IAAM,EAAO,EAAW,EAAO,EAAO,CAAI,EAC1C,OAAO,MAAM,QAAQ,CAAI,EACrB,CAAE,KAAM,GAAO,QAAS,GAAM,QAAS,GAAM,MAAK,EAClD,CAAE,KAAM,GAAO,QAAS,GAAM,MAAK,CACzC"}
1
+ {"version":3,"file":"flatMap.js","names":[],"sources":["../src/flatMap.ts"],"sourcesContent":["import type { LazyCallback } from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param data - The items to map and flatten.\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(data, callbackfn)\n * @example\n * flatMap([1, 2, 3], x => [x, x * 10]) // => [1, 10, 2, 20, 3, 30]\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n data: readonly T[],\n callbackfn: (input: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[];\n\n/**\n * Returns a new array formed by applying a given callback function to each\n * element of the array, and then flattening the result by one level. It is\n * identical to a `map` followed by a `flat` of depth 1\n * (`flat(map(data, ...args))`), but slightly more efficient than calling those\n * two methods separately. Equivalent to `Array.prototype.flatMap`.\n *\n * @param callbackfn - A function to execute for each element in the array. It\n * should return an array containing new elements of the new array, or a single\n * non-array value to be added to the new array.\n * @returns A new array with each element being the result of the callback\n * function and flattened by a depth of 1.\n * @signature\n * flatMap(callbackfn)(data)\n * @example\n * pipe([1, 2, 3], flatMap(x => [x, x * 10])) // => [1, 10, 2, 20, 3, 30]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function flatMap<T, U>(\n callbackfn: LazyCallback<readonly T[], readonly U[] | U>,\n): (data: readonly T[]) => U[];\n\nexport function flatMap(...args: readonly unknown[]): unknown {\n return purry(flatMapImplementation, args, lazyImplementation);\n}\n\nconst flatMapImplementation = <T, U>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => readonly U[] | U,\n): U[] => data.flatMap(callbackfn);\n\nconst lazyImplementation =\n <T, K>(\n callbackfn: (\n input: T,\n index: number,\n data: readonly T[],\n ) => K | readonly K[],\n ): LazyEvaluator<T, K> =>\n // @ts-expect-error [ts2322] - We need to make LazyMany better so it accommodate the typing here...\n (value, index, data) => {\n const next = callbackfn(value, index, data);\n return Array.isArray(next)\n ? { done: false, hasNext: true, hasMany: true, next }\n : { done: false, hasNext: true, next };\n };\n"],"mappings":"mCAsDA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAO,EAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,MAAM,GACJ,EACA,IACQ,EAAK,QAAQ,CAAU,EAE3B,EAEF,IAOD,EAAO,EAAO,IAAS,CACtB,IAAM,EAAO,EAAW,EAAO,EAAO,CAAI,EAC1C,OAAO,MAAM,QAAQ,CAAI,EACrB,CAAE,KAAM,GAAO,QAAS,GAAM,QAAS,GAAM,MAAK,EAClD,CAAE,KAAM,GAAO,QAAS,GAAM,MAAK,CACzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"forEach.cjs","names":["purry"],"sources":["../src/forEach.ts"],"sourcesContent":["import type { Writable } from \"type-fest\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. When not used in a `pipe` the\n * returned array is equal to the input array (by reference), and not a shallow\n * copy of it!\n *\n * @param data - The values that would be iterated on.\n * @param callbackfn - A function to execute for each element in the array.\n * @signature\n * forEach(data, callbackfn)\n * @example\n * forEach([1, 2, 3], x => {\n * console.log(x)\n * });\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n data: T,\n callbackfn: (value: T[number], index: number, data: T) => void,\n): void;\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. The returned array is the\n * same reference as the input array, and not a shallow copy of it!\n *\n * @param callbackfn - A function to execute for each element in the array.\n * @returns The original array (the ref itself, not a shallow copy of it).\n * @signature\n * forEach(callbackfn)(data)\n * @example\n * pipe(\n * [1, 2, 3],\n * forEach(x => {\n * console.log(x)\n * })\n * ) // => [1, 2, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n callbackfn: (value: T[number], index: number, data: T) => void,\n): (data: T) => Writable<T>;\n\nexport function forEach(...args: readonly unknown[]): unknown {\n return purry(forEachImplementation, args, lazyImplementation);\n}\n\nfunction forEachImplementation<T>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n): T[] {\n // eslint-disable-next-line unicorn/no-for-each -- We are intentionally proxying the built in forEach, it's up to the user to decide if they want to use a for loop instead.\n data.forEach(callbackfn);\n // @ts-expect-error [ts4104] - Because the dataFirst signature returns void this is only a problem when the dataLast function is used **outside** of a pipe; for these cases we warn the user that this is happening.\n return data;\n}\n\nconst lazyImplementation =\n <T>(\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n ): LazyEvaluator<T> =>\n (value, index, data) => {\n callbackfn(value, index, data);\n return { done: false, hasNext: true, next: value };\n };\n"],"mappings":"kGA0DA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAOA,EAAAA,MAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,SAAS,EACP,EACA,EACK,CAIL,OAFA,EAAK,QAAQ,CAAU,EAEhB,CACT,CAEA,MAAM,EAEF,IAED,EAAO,EAAO,KACb,EAAW,EAAO,EAAO,CAAI,EACtB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM"}
1
+ {"version":3,"file":"forEach.cjs","names":["purry"],"sources":["../src/forEach.ts"],"sourcesContent":["import type { Writable } from \"type-fest\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyCallback } from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. When not used in a `pipe` the\n * returned array is equal to the input array (by reference), and not a shallow\n * copy of it!\n *\n * @param data - The values that would be iterated on.\n * @param callbackfn - A function to execute for each element in the array.\n * @signature\n * forEach(data, callbackfn)\n * @example\n * forEach([1, 2, 3], x => {\n * console.log(x)\n * });\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n data: T,\n callbackfn: (value: T[number], index: number, data: T) => void,\n): void;\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. The returned array is the\n * same reference as the input array, and not a shallow copy of it!\n *\n * @param callbackfn - A function to execute for each element in the array.\n * @returns The original array (the ref itself, not a shallow copy of it).\n * @signature\n * forEach(callbackfn)(data)\n * @example\n * pipe(\n * [1, 2, 3],\n * forEach(x => {\n * console.log(x)\n * })\n * ) // => [1, 2, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n callbackfn: LazyCallback<T, void>,\n): (data: T) => Writable<T>;\n\nexport function forEach(...args: readonly unknown[]): unknown {\n return purry(forEachImplementation, args, lazyImplementation);\n}\n\nfunction forEachImplementation<T>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n): T[] {\n // eslint-disable-next-line unicorn/no-for-each -- We are intentionally proxying the built in forEach, it's up to the user to decide if they want to use a for loop instead.\n data.forEach(callbackfn);\n // @ts-expect-error [ts4104] - Because the dataFirst signature returns void this is only a problem when the dataLast function is used **outside** of a pipe; for these cases we warn the user that this is happening.\n return data;\n}\n\nconst lazyImplementation =\n <T>(\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n ): LazyEvaluator<T> =>\n (value, index, data) => {\n callbackfn(value, index, data);\n return { done: false, hasNext: true, next: value };\n };\n"],"mappings":"kGA2DA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAOA,EAAAA,MAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,SAAS,EACP,EACA,EACK,CAIL,OAFA,EAAK,QAAQ,CAAU,EAEhB,CACT,CAEA,MAAM,EAEF,IAED,EAAO,EAAO,KACb,EAAW,EAAO,EAAO,CAAI,EACtB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"forEach.js","names":[],"sources":["../src/forEach.ts"],"sourcesContent":["import type { Writable } from \"type-fest\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. When not used in a `pipe` the\n * returned array is equal to the input array (by reference), and not a shallow\n * copy of it!\n *\n * @param data - The values that would be iterated on.\n * @param callbackfn - A function to execute for each element in the array.\n * @signature\n * forEach(data, callbackfn)\n * @example\n * forEach([1, 2, 3], x => {\n * console.log(x)\n * });\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n data: T,\n callbackfn: (value: T[number], index: number, data: T) => void,\n): void;\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. The returned array is the\n * same reference as the input array, and not a shallow copy of it!\n *\n * @param callbackfn - A function to execute for each element in the array.\n * @returns The original array (the ref itself, not a shallow copy of it).\n * @signature\n * forEach(callbackfn)(data)\n * @example\n * pipe(\n * [1, 2, 3],\n * forEach(x => {\n * console.log(x)\n * })\n * ) // => [1, 2, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n callbackfn: (value: T[number], index: number, data: T) => void,\n): (data: T) => Writable<T>;\n\nexport function forEach(...args: readonly unknown[]): unknown {\n return purry(forEachImplementation, args, lazyImplementation);\n}\n\nfunction forEachImplementation<T>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n): T[] {\n // eslint-disable-next-line unicorn/no-for-each -- We are intentionally proxying the built in forEach, it's up to the user to decide if they want to use a for loop instead.\n data.forEach(callbackfn);\n // @ts-expect-error [ts4104] - Because the dataFirst signature returns void this is only a problem when the dataLast function is used **outside** of a pipe; for these cases we warn the user that this is happening.\n return data;\n}\n\nconst lazyImplementation =\n <T>(\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n ): LazyEvaluator<T> =>\n (value, index, data) => {\n callbackfn(value, index, data);\n return { done: false, hasNext: true, next: value };\n };\n"],"mappings":"mCA0DA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAO,EAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,SAAS,EACP,EACA,EACK,CAIL,OAFA,EAAK,QAAQ,CAAU,EAEhB,CACT,CAEA,MAAM,EAEF,IAED,EAAO,EAAO,KACb,EAAW,EAAO,EAAO,CAAI,EACtB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM"}
1
+ {"version":3,"file":"forEach.js","names":[],"sources":["../src/forEach.ts"],"sourcesContent":["import type { Writable } from \"type-fest\";\nimport type { IterableContainer } from \"./internal/types/IterableContainer\";\nimport type { LazyCallback } from \"./internal/types/LazyCallback\";\nimport type { LazyEvaluator } from \"./internal/types/LazyEvaluator\";\nimport { purry } from \"./purry\";\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. When not used in a `pipe` the\n * returned array is equal to the input array (by reference), and not a shallow\n * copy of it!\n *\n * @param data - The values that would be iterated on.\n * @param callbackfn - A function to execute for each element in the array.\n * @signature\n * forEach(data, callbackfn)\n * @example\n * forEach([1, 2, 3], x => {\n * console.log(x)\n * });\n * @dataFirst\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n data: T,\n callbackfn: (value: T[number], index: number, data: T) => void,\n): void;\n\n/**\n * Executes a provided function once for each array element. Equivalent to\n * `Array.prototype.forEach`.\n *\n * The dataLast version returns the original array (instead of not returning\n * anything (`void`)) to allow using it in a pipe. The returned array is the\n * same reference as the input array, and not a shallow copy of it!\n *\n * @param callbackfn - A function to execute for each element in the array.\n * @returns The original array (the ref itself, not a shallow copy of it).\n * @signature\n * forEach(callbackfn)(data)\n * @example\n * pipe(\n * [1, 2, 3],\n * forEach(x => {\n * console.log(x)\n * })\n * ) // => [1, 2, 3]\n * @dataLast\n * @lazy\n * @category Array\n */\nexport function forEach<T extends IterableContainer>(\n callbackfn: LazyCallback<T, void>,\n): (data: T) => Writable<T>;\n\nexport function forEach(...args: readonly unknown[]): unknown {\n return purry(forEachImplementation, args, lazyImplementation);\n}\n\nfunction forEachImplementation<T>(\n data: readonly T[],\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n): T[] {\n // eslint-disable-next-line unicorn/no-for-each -- We are intentionally proxying the built in forEach, it's up to the user to decide if they want to use a for loop instead.\n data.forEach(callbackfn);\n // @ts-expect-error [ts4104] - Because the dataFirst signature returns void this is only a problem when the dataLast function is used **outside** of a pipe; for these cases we warn the user that this is happening.\n return data;\n}\n\nconst lazyImplementation =\n <T>(\n callbackfn: (value: T, index: number, data: readonly T[]) => void,\n ): LazyEvaluator<T> =>\n (value, index, data) => {\n callbackfn(value, index, data);\n return { done: false, hasNext: true, next: value };\n };\n"],"mappings":"mCA2DA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAO,EAAM,EAAuB,EAAM,CAAkB,CAC9D,CAEA,SAAS,EACP,EACA,EACK,CAIL,OAFA,EAAK,QAAQ,CAAU,EAEhB,CACT,CAEA,MAAM,EAEF,IAED,EAAO,EAAO,KACb,EAAW,EAAO,EAAO,CAAI,EACtB,CAAE,KAAM,GAAO,QAAS,GAAM,KAAM,CAAM"}