{"id":13769262,"url":"https://selfrefactor.github.io/rambda/","last_synced_at":"2025-05-11T01:31:46.691Z","repository":{"id":39898264,"uuid":"79035508","full_name":"selfrefactor/rambda","owner":"selfrefactor","description":"Typescript focused FP library similar to Remeda and Rambda","archived":false,"fork":false,"pushed_at":"2025-05-09T08:30:38.000Z","size":14234,"stargazers_count":1719,"open_issues_count":2,"forks_count":89,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-09T09:30:11.064Z","etag":null,"topics":["fp","functional","functional-programming","functions","lodash","ramda","typescript","utility","utils"],"latest_commit_sha":null,"homepage":"https://selfrefactor.github.io/rambda/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selfrefactor.png","metadata":{"files":{"readme":".github/README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-01-15T13:50:45.000Z","updated_at":"2025-05-08T15:01:15.000Z","dependencies_parsed_at":"2023-10-02T08:02:05.330Z","dependency_job_id":"7bdbfbce-d704-48c3-90ae-a55b80e3fce2","html_url":"https://github.com/selfrefactor/rambda","commit_stats":{"total_commits":2106,"total_committers":62,"mean_commits":33.96774193548387,"dds":"0.23646723646723644","last_synced_commit":"99e3846c3be40afe904257af0713e96fbf4a1eb5"},"previous_names":[],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selfrefactor%2Frambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selfrefactor%2Frambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selfrefactor%2Frambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selfrefactor%2Frambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selfrefactor","download_url":"https://codeload.github.com/selfrefactor/rambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253351768,"owners_count":21895027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fp","functional","functional-programming","functions","lodash","ramda","typescript","utility","utils"],"created_at":"2024-08-03T17:00:20.583Z","updated_at":"2025-05-11T01:31:46.662Z","avatar_url":"https://github.com/selfrefactor.png","language":"JavaScript","funding_links":[],"categories":["Showcase"],"sub_categories":[],"readme":"# Rambda\n\n`Rambda` is TypeScript-focused utility library similar to `Remeda` and `Lodash`. \n\nInitially it started as faster alternative to functional programming library `Ramda`, but in order to address many TypeScript issues, now `Rambda` takes a separate path. - [Documentation](https://selfrefactor.github.io/rambda/#/)\n\n![Commit activity](https://img.shields.io/github/commit-activity/y/selfrefactor/rambda)\n![Library size](https://img.shields.io/bundlephobia/minzip/rambda)\n[![install size](https://packagephobia.com/badge?p=rambda)](https://packagephobia.com/result?p=rambda)\n[![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](https://github.com/selfrefactor/rambda/pulls)\n[![GitHub contributors](https://img.shields.io/github/contributors/selfrefactor/rambda.svg)](https://github.com/selfrefactor/rambda/graphs/contributors)\n\n## ❯ Example use\n\n```javascript\nimport { pipe, map, filter } from 'rambda'\n\nconst result = pipe(\n\t[1, 2, 3, 4],\n  filter(x =\u003e x \u003e 2),\n  map(x =\u003e x * 2),\n)\n// =\u003e [6, 8]\n```\n\nYou can test this example in \u003ca href=\"https://rambda.now.sh?const%20result%20%3D%20R.compose(%0A%20%20R.map(x%20%3D%3E%20x%20*%202)%2C%0A%20%20R.filter(x%20%3D%3E%20x%20%3E%202)%0A)(%5B1%2C%202%2C%203%2C%204%5D)%0A%0A%2F%2F%20%3D%3E%20%5B6%2C%208%5D\"\u003eRambda's REPL\u003c/a\u003e\n\n* [API](#api)\n* [Changelog](#-changelog)\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#-example-use)\n\n## ❯ Rambda's features\n\n## ❯ Goals\n\n### Typescript focus\n\nMixing `Functional Programming` and `TypeScript` is not easy.\n\nOne way to solve this is to focus what can be actually achieved and refrain from what is not possible.\n\n### `R.pipe` as the main way to use Rambda\n\n- All methods are meant to be used as part of `R.pipe` chain\n\n- This is the main purpose of functional programming, i.e. to pass data through a chain of functions.\n\n- Having `R.pipe(input, ...fns)` helps TypeScript to infer the types of the input and the output.\n\nHere is one example why `R.pipe` is better than `Ramda.pipe`:\n\n```ts\nconst list = [1, 2, 3];\n\nit('within pipe', () =\u003e {\n\tconst result = pipe(\n\t\tlist,\n\t\tfilter((x) =\u003e {\n\t\t\tx; // $ExpectType number\n\t\t\treturn x \u003e 1;\n\t\t}),\n\t);\n\tresult; // $ExpectType number[]\n});\nit('within Ramda.pipe requires explicit types', () =\u003e {\n\tRamda.pipe(\n\t\t(x) =\u003e x,\n\t\tfilter\u003cnumber\u003e((x) =\u003e {\n\t\t\tx; // $ExpectType number\n\t\t\treturn x \u003e 1;\n\t\t}),\n\t\tfilter((x: number) =\u003e {\n\t\t\tx; // $ExpectType number\n\t\t\treturn x \u003e 1;\n\t\t}),\n\t)(list);\n});\n```\n\n### Keep only the most useful methods\n\nThe idea is to give `TypeScript` users only the most useful methods and let them implement the rest. No magic logic methods that are hard to remember. You shouldn't need to read the documentation to understand what a method does. Its name and signature should be enough.\n\n- Methods that are simply to remember only by its name. Complex logic shouldn't be part of utility library, but part of your codebase.\n\n- Keep only methods which are both useful and which behaviour is obvious from its name. For example, `R.innerJoin` is kept, but `R.identical`, `R.move` is removed. Methods such as `R.toLower`, `R.length` provide little value. Such method are omitted from Rambda on purpose.\n\n- Some generic methods such as `curry` and `assoc` is not easy to be expressed in TypeScript. For this reason `Rambda` omits such methods.\n\n- No `R.cond` or `R.ifElse` as they make the chain less readable.\n\n- No `R.length` as it adds very little value.\n\n- No `R.difference` as user must remember the order of the inputs, i.e. which is compared to and which is compared against.\n\n### One way to use each method\n\nBecause of the focus on `R.pipe`, there is only one way to use each method. This helps with testing and also with TypeScript definitions.\n\n- All methods that 2 inputs, will have to be called with `R.methodName(input1)(input2)`\n- All methods that 3 inputs, will have to be called with `R.methodName(input1, input2)(input3)`\n\n### Immutable TS definitions\n\nYou can use immutable version of Rambda definitions, which is linted with ESLint `functional/prefer-readonly-type` plugin.\n\n```\nimport {filter} from 'rambda/immutable'\n```\n\n### Deno support \n\n```\nimport * as R from \"https://deno.land/x/rambda/mod.ts\";\n\nR.filter(x =\u003e x \u003e 1)([1, 2, 3])\n```\n\n### Dot notation for `R.path`\n\nStandard usage of `R.path` is `R.path(['a', 'b'])({a: {b: 1} })`.\n\nIn **Rambda** you have the choice to use dot notation(which is arguably more readable):\n\n```\nR.path('a.b')({a: {b: 1} })\n```\n\nPlease note that since path input is turned into array, i.e. if you want `R.path(['a','1', 'b'])({a: {'1': {b: 2}}})` to return `2`, you will have to pass array path, not string path. If you pass `a.1.b`, it will turn path input to `['a', 1, 'b']`.\n\n### Comma notation for `R.pick` and `R.omit`\n\nSimilar to dot notation, but the separator is comma(`,`) instead of dot(`.`).\n\n```\nR.pick('a,b', {a: 1 , b: 2, c: 3} })\n// No space allowed between properties\n```\n\n### Fast performance compared to Ramda\n\nSince `Rambda` methods doesn't use so many internals, it is faster than `Ramda`.\nPrior to version `10`, benchmark summary was included, but now the main selling point is the TypeScript focus, not performance so this is no longer included.\n\n### Differences between Rambda and Ramda\n\nUp until version `9.4.2`, the aim of Rambda was to match as much as possible the Ramda API.\n\nDocumentation site of `Rambda` version `9.4.2` is available [here](https://selfrefactor.github.io/rambda-v9/).\n\nFrom version `10.0.0` onwards, Rambda will start to diverge from Ramda in order to address some of the issues that Ramda has.\n\n\u003cdetails\u003e\n\u003csummary\u003e\n\tRamda issues\n\u003c/summary\u003e\n\n-- Typescript support - this is the main reason for the divergence. Most of design decisions in Rambda are made with Typescript in mind.\n\n-- Methods that imply side-effect, which is not FP oriented, e.g. `R.forEach`.\n\n-- Naming of methods that doesn't match developer's expectation, such as `R.chain`, which should be called `flatMap`.\n\n-- Naming of methods is sometimes too generic to be remembered such as `R.update`, `R.modify`, `R.where`.\n\n-- Methods that are already present in standard JavaScript, such as `R.toLower`, `R.length`.\n\n-- `R.compose` doesn't have the best possible TypeScript support.\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#-rambdas-features)\n\n## API\n\n### addProp\n\n```typescript\n\naddProp\u003cT extends object, P extends PropertyKey, V extends unknown\u003e(\n\tprop: P,\n\tvalue: V\n): (obj: T) =\u003e MergeTypes\u003cT \u0026 Record\u003cP, V\u003e\u003e\n```\n\nIt adds new key-value pair to the object.\n\n```javascript\nconst result = R.pipe(\n\t{ a: 1, b: 'foo' }, \n\tR.addProp('c', 3)\n)\n// =\u003e { a: 1, b: 'foo', c: 3 }\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.pipe(%0A%09%7B%20a%3A%201%2C%20b%3A%20'foo'%20%7D%2C%20%0A%09R.addProp('c'%2C%203)%0A)%0A%2F%2F%20%3D%3E%20%7B%20a%3A%201%2C%20b%3A%20'foo'%2C%20c%3A%203%20%7D\"\u003eTry this \u003cstrong\u003eR.addProp\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\naddProp\u003cT extends object, P extends PropertyKey, V extends unknown\u003e(\n\tprop: P,\n\tvalue: V\n): (obj: T) =\u003e MergeTypes\u003cT \u0026 Record\u003cP, V\u003e\u003e;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.addProp\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function addProp(key, value) {\n  return obj =\u003e ({ ...obj, [key]: value })\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { addProp } from \"./addProp.js\"\n\ntest('happy', () =\u003e {\n\tconst result = addProp('a', 1)({ b: 2 })\n\tconst expected = { a: 1, b: 2 }\n\n\texpect(result).toEqual(expected)\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { addProp, pipe } from 'rambda'\n\nit('R.addProp', () =\u003e {\n\tconst result = pipe({ a: 1, b: 'foo' }, addProp('c', 3))\n\tresult.a // $ExpectType number\n\tresult.b // $ExpectType string\n\tresult.c // $ExpectType number\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#addProp)\n\n### all\n\n```typescript\n\nall\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e boolean\n```\n\nIt returns `true`, if all members of array `list` returns `true`, when applied as argument to `predicate` function.\n\n```javascript\nconst list = [ 0, 1, 2, 3, 4 ]\nconst predicate = x =\u003e x \u003e -1\n\nconst result = R.pipe(\n\tlist,\n\tR.all(predicate)\n) // =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%200%2C%201%2C%202%2C%203%2C%204%20%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%20-1%0A%0Aconst%20result%20%3D%20R.pipe(%0A%09list%2C%0A%09R.all(predicate)%0A)%20%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.all\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nall\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e boolean;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.all\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function all(predicate) {\n  return list =\u003e {\n    for (let i = 0; i \u003c list.length; i++) {\n      if (!predicate(list[i])) {\n        return false\n      }\n    }\n\n    return true\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { all } from './all.js'\n\nconst list = [0, 1, 2, 3, 4]\n\ntest('when true', () =\u003e {\n  const fn = x =\u003e x \u003e -1\n\n  expect(all(fn)(list)).toBeTruthy()\n})\n\ntest('when false', () =\u003e {\n  const fn = x =\u003e x \u003e 2\n\n  expect(all(fn)(list)).toBeFalsy()\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport * as R from 'rambda'\n\ndescribe('all', () =\u003e {\n  it('happy', () =\u003e {\n    const result = R.pipe(\n      [1, 2, 3],\n      R.all(x =\u003e {\n        x // $ExpectType number\n        return x \u003e 0\n      }),\n    )\n    result // $ExpectType boolean\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#all)\n\n### allPass\n\n```typescript\n\nallPass\u003cF extends (...args: any[]) =\u003e boolean\u003e(predicates: readonly F[]): F\n```\n\nIt returns `true`, if all functions of `predicates` return `true`, when `input` is their argument.\n\n```javascript\nconst list = [[1, 2, 3, 4], [3, 4, 5]]\nconst result = R.pipe(\n\tlist,\n\tR.filter(R.allPass([R.includes(2), R.includes(3)]))\n) // =\u003e [[1, 2, 3, 4]]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%5B1%2C%202%2C%203%2C%204%5D%2C%20%5B3%2C%204%2C%205%5D%5D%0Aconst%20result%20%3D%20R.pipe(%0A%09list%2C%0A%09R.filter(R.allPass(%5BR.includes(2)%2C%20R.includes(3)%5D))%0A)%20%2F%2F%20%3D%3E%20%5B%5B1%2C%202%2C%203%2C%204%5D%5D\"\u003eTry this \u003cstrong\u003eR.allPass\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nallPass\u003cF extends (...args: any[]) =\u003e boolean\u003e(predicates: readonly F[]): F;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.allPass\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function allPass(predicates) {\n  return input =\u003e {\n    let counter = 0\n    while (counter \u003c predicates.length) {\n      if (!predicates[counter](input)) {\n        return false\n      }\n      counter++\n    }\n\n    return true\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { allPass } from './allPass.js'\nimport { filter } from './filter.js'\nimport { includes } from './includes.js'\nimport { pipe } from './pipe.js'\n\nconst list = [\n  [1, 2, 3, 4],\n  [3, 4, 5],\n]\ntest('happy', () =\u003e {\n  const result = pipe(list, filter(allPass([includes(2), includes(3)])))\n  expect(result).toEqual([[1, 2, 3, 4]])\n})\n\ntest('when returns false', () =\u003e {\n  const result = pipe(list, filter(allPass([includes(12), includes(31)])))\n  expect(result).toEqual([])\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport * as R from 'rambda'\n\ndescribe('allPass', () =\u003e {\n  it('happy', () =\u003e {\n    const list = [\n      [1, 2, 3, 4],\n      [3, 4, 5],\n    ]\n    const result = R.pipe(list, R.map(R.allPass([R.includes(3), R.includes(4)])))\n    result // $ExpectType boolean[]\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#allPass)\n\n### any\n\n```typescript\n\nany\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e boolean\n```\n\nIt returns `true`, if at least one member of `list` returns true, when passed to a `predicate` function.\n\n```javascript\nconst list = [1, 2, 3]\nconst predicate = x =\u003e x * x \u003e 8\nR.any(fn)(list)\n// =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B1%2C%202%2C%203%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20*%20x%20%3E%208%0Aconst%20result%20%3D%20R.any(fn)(list)%0A%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.any\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nany\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e boolean;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.any\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function any(predicate) {\n  return list =\u003e {\n    let counter = 0\n    while (counter \u003c list.length) {\n      if (predicate(list[counter], counter)) {\n        return true\n      }\n      counter++\n    }\n\n    return false\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { any } from './any.js'\n\nconst list = [1, 2, 3]\n\ntest('happy', () =\u003e {\n  expect(any(x =\u003e x \u003e 2)(list)).toBeTruthy()\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { any, pipe } from 'rambda'\n\nit('R.any', () =\u003e {\n  const result = pipe(\n    [1, 2, 3],\n    any(x =\u003e {\n      x // $ExpectType number\n      return x \u003e 2\n    }),\n  )\n  result // $ExpectType boolean\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#any)\n\n### anyPass\n\n```typescript\n\nanyPass\u003cT, TF1 extends T, TF2 extends T\u003e(\n  predicates: [(a: T) =\u003e a is TF1, (a: T) =\u003e a is TF2],\n): (a: T) =\u003e a is TF1 | TF2\n```\n\nIt accepts list of `predicates` and returns a function. This function with its `input` will return `true`, if any of `predicates` returns `true` for this `input`.\n\n\u003e :boom: Function accepts only one input, but in Ramda it accepts indefinite number of arguments.\n\n```javascript\nconst isBig = x =\u003e x \u003e 20\nconst isOdd = x =\u003e x % 2 === 1\nconst input = 11\n\nconst fn = R.anyPass(\n  [isBig, isOdd]\n)\n\nconst result = fn(input) \n// =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20isBig%20%3D%20x%20%3D%3E%20x%20%3E%2020%0Aconst%20isOdd%20%3D%20x%20%3D%3E%20x%20%25%202%20%3D%3D%3D%201%0Aconst%20input%20%3D%2011%0A%0Aconst%20fn%20%3D%20R.anyPass(%0A%20%20%5BisBig%2C%20isOdd%5D%0A)%0A%0Aconst%20result%20%3D%20fn(input)%20%0A%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.anyPass\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nanyPass\u003cT, TF1 extends T, TF2 extends T\u003e(\n  predicates: [(a: T) =\u003e a is TF1, (a: T) =\u003e a is TF2],\n): (a: T) =\u003e a is TF1 | TF2;\nanyPass\u003cT, TF1 extends T, TF2 extends T, TF3 extends T\u003e(\n  predicates: [(a: T) =\u003e a is TF1, (a: T) =\u003e a is TF2, (a: T) =\u003e a is TF3],\n): (a: T) =\u003e a is TF1 | TF2 | TF3;\nanyPass\u003cT, TF1 extends T, TF2 extends T, TF3 extends T\u003e(\n  predicates: [(a: T) =\u003e a is TF1, (a: T) =\u003e a is TF2, (a: T) =\u003e a is TF3],\n): (a: T) =\u003e a is TF1 | TF2 | TF3;\nanyPass\u003cT, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T\u003e(\n  predicates: [(a: T) =\u003e a is TF1, (a: T) =\u003e a is TF2, (a: T) =\u003e a is TF3, (a: T) =\u003e a is TF4],\n): (a: T) =\u003e a is TF1 | TF2 | TF3 | TF4;\nanyPass\u003cT, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T\u003e(\n  predicates: [\n    (a: T) =\u003e a is TF1,\n    (a: T) =\u003e a is TF2,\n    (a: T) =\u003e a is TF3,\n    (a: T) =\u003e a is TF4,\n    (a: T) =\u003e a is TF5\n  ],\n): (a: T) =\u003e a is TF1 | TF2 | TF3 | TF4 | TF5;\nanyPass\u003cT, TF1 extends T, TF2 extends T, TF3 extends T, TF4 extends T, TF5 extends T, TF6 extends T\u003e(\n  predicates: [\n    (a: T) =\u003e a is TF1,\n    (a: T) =\u003e a is TF2,\n    (a: T) =\u003e a is TF3,\n    (a: T) =\u003e a is TF4,\n    (a: T) =\u003e a is TF5,\n    (a: T) =\u003e a is TF6\n  ],\n): (a: T) =\u003e a is TF1 | TF2 | TF3 | TF4 | TF5 | TF6;\nanyPass\u003cF extends (...args: any[]) =\u003e boolean\u003e(predicates: readonly F[]): F;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.anyPass\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function anyPass(predicates) {\n  return input =\u003e {\n    let counter = 0\n    while (counter \u003c predicates.length) {\n      if (predicates[counter](input)) {\n        return true\n      }\n      counter++\n    }\n\n    return false\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { anyPass } from './anyPass.js'\n\ntest('happy', () =\u003e {\n  const rules = [x =\u003e typeof x === 'string', x =\u003e x \u003e 10]\n  const predicate = anyPass(rules)\n  expect(predicate('foo')).toBeTruthy()\n  expect(predicate(6)).toBeFalsy()\n})\n\ntest('happy', () =\u003e {\n  const rules = [x =\u003e typeof x === 'string', x =\u003e x \u003e 10]\n\n  expect(anyPass(rules)(11)).toBeTruthy()\n  expect(anyPass(rules)(undefined)).toBeFalsy()\n})\n\nconst obj = {\n  a: 1,\n  b: 2,\n}\n\ntest('when returns true', () =\u003e {\n  const conditionArr = [val =\u003e val.a === 1, val =\u003e val.a === 2]\n\n  expect(anyPass(conditionArr)(obj)).toBeTruthy()\n})\n\ntest('when returns false', () =\u003e {\n  const conditionArr = [val =\u003e val.a === 2, val =\u003e val.b === 3]\n\n  expect(anyPass(conditionArr)(obj)).toBeFalsy()\n})\n\ntest('with empty predicates list', () =\u003e {\n  expect(anyPass([])(3)).toBeFalsy()\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { anyPass, filter } from 'rambda'\n\ndescribe('anyPass', () =\u003e {\n  it('issue #604', () =\u003e {\n    const plusEq = (w: number, x: number, y: number, z: number) =\u003e w + x === y + z\n    const result = anyPass([plusEq])(3, 3, 3, 3)\n\n    result // $ExpectType boolean\n  })\n  it('issue #642', () =\u003e {\n    const isGreater = (num: number) =\u003e num \u003e 5\n    const pred = anyPass([isGreater])\n    const xs = [0, 1, 2, 3]\n\n    const filtered1 = filter(pred)(xs)\n    filtered1 // $ExpectType number[]\n    const filtered2 = xs.filter(pred)\n    filtered2 // $ExpectType number[]\n  })\n  it('functions as a type guard', () =\u003e {\n    const isString = (x: unknown): x is string =\u003e typeof x === 'string'\n    const isNumber = (x: unknown): x is number =\u003e typeof x === 'number'\n    const isBoolean = (x: unknown): x is boolean =\u003e typeof x === 'boolean'\n\n    const isStringNumberOrBoolean = anyPass([isString, isNumber, isBoolean])\n\n    const aValue: unknown = 1\n\n    if (isStringNumberOrBoolean(aValue)) {\n      aValue // $ExpectType string | number | boolean\n    }\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#anyPass)\n\n### append\n\n```typescript\n\nappend\u003cT\u003e(el: T): (list: T[]) =\u003e T[]\n```\n\nIt adds element `x` at the end of `iterable`.\n\n```javascript\nconst x = 'foo'\n\nconst result = R.append(x, ['bar', 'baz'])\n// =\u003e ['bar', 'baz', 'foo']\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20x%20%3D%20'foo'%0A%0Aconst%20result%20%3D%20R.append(x%2C%20%5B'bar'%2C%20'baz'%5D)%0A%2F%2F%20%3D%3E%20%5B'bar'%2C%20'baz'%2C%20'foo'%5D\"\u003eTry this \u003cstrong\u003eR.append\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nappend\u003cT\u003e(el: T): (list: T[]) =\u003e T[];\nappend\u003cT\u003e(el: T): (list: readonly T[]) =\u003e T[];\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.append\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { cloneList } from './_internals/cloneList.js'\n\nexport function append(x) {\n  return list =\u003e {\n    const clone = cloneList(list)\n    clone.push(x)\n\n    return clone\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { append } from './append.js'\n\ntest('happy', () =\u003e {\n  expect(append('tests')(['write', 'more'])).toEqual(['write', 'more', 'tests'])\n})\n\ntest('append to empty array', () =\u003e {\n  expect(append('tests')([])).toEqual(['tests'])\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { append, pipe, prepend } from 'rambda'\n\nconst listOfNumbers = [1, 2, 3]\n\ndescribe('R.append/R.prepend', () =\u003e {\n  it('happy', () =\u003e {\n    const result = pipe(listOfNumbers, append(4), prepend(0))\n    result // $ExpectType number[]\n  })\n  it('with object', () =\u003e {\n    const result = pipe([{ a: 1 }], append({ a: 10 }), prepend({ a: 20 }))\n    result // $ExpectType { a: number; }[]\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#append)\n\n### ascend\n\nHelper function to be used with `R.sort` to sort list in ascending order.\n\n```javascript\nconst result = R.pipe(\n\t[{a: 1}, {a: 2}, {a: 0}],\n\tR.sort(R.ascend(R.prop('a')))\n)\n// =\u003e [{a: 0}, {a: 1}, {a: 2}]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.pipe(%0A%09%5B%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%2C%20%7Ba%3A%200%7D%5D%2C%0A%09R.sort(R.ascend(R.prop('a')))%0A)%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A%200%7D%2C%20%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%5D\"\u003eTry this \u003cstrong\u003eR.ascend\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#ascend)\n\n### checkObjectWithSpec\n\n```typescript\n\ncheckObjectWithSpec\u003cT\u003e(spec: T): \u003cU\u003e(testObj: U) =\u003e boolean\n```\n\nIt returns `true` if all each property in `conditions` returns `true` when applied to corresponding property in `input` object.\n\n```javascript\nconst condition = R.checkObjectWithSpec({\n  a : x =\u003e typeof x === \"string\",\n  b : x =\u003e x === 4\n})\nconst input = {\n  a : \"foo\",\n  b : 4,\n  c : 11,\n}\n\nconst result = condition(input) \n// =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20condition%20%3D%20R.checkObjectWithSpec(%7B%0A%20%20a%20%3A%20x%20%3D%3E%20typeof%20x%20%3D%3D%3D%20%22string%22%2C%0A%20%20b%20%3A%20x%20%3D%3E%20x%20%3D%3D%3D%204%0A%7D)%0Aconst%20input%20%3D%20%7B%0A%20%20a%20%3A%20%22foo%22%2C%0A%20%20b%20%3A%204%2C%0A%20%20c%20%3A%2011%2C%0A%7D%0A%0Aconst%20result%20%3D%20condition(input)%20%0A%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.checkObjectWithSpec\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ncheckObjectWithSpec\u003cT\u003e(spec: T): \u003cU\u003e(testObj: U) =\u003e boolean;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.checkObjectWithSpec\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function checkObjectWithSpec(conditions) {\n  return input =\u003e {\n    let shouldProceed = true\n    for (const prop in conditions) {\n      if (!shouldProceed) {\n        continue\n      }\n      const result = conditions[prop](input[prop])\n      if (shouldProceed \u0026\u0026 result === false) {\n        shouldProceed = false\n      }\n    }\n\n    return shouldProceed\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { checkObjectWithSpec } from './checkObjectWithSpec.js'\nimport { equals } from './equals.js'\n\ntest('when true', () =\u003e {\n  const result = checkObjectWithSpec({\n    a: equals('foo'),\n    b: equals('bar'),\n  })({\n    a: 'foo',\n    b: 'bar',\n    x: 11,\n    y: 19,\n  })\n\n  expect(result).toBeTruthy()\n})\n\ntest('when false | early exit', () =\u003e {\n  let counter = 0\n  const equalsFn = expected =\u003e input =\u003e {\n    counter++\n\n    return input === expected\n  }\n  const predicate = checkObjectWithSpec({\n    a: equalsFn('foo'),\n    b: equalsFn('baz'),\n  })\n  expect(\n    predicate({\n      a: 'notfoo',\n      b: 'notbar',\n    }),\n  ).toBeFalsy()\n  expect(counter).toBe(1)\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { checkObjectWithSpec, equals } from 'rambda'\n\ndescribe('R.checkObjectWithSpec', () =\u003e {\n  it('happy', () =\u003e {\n    const input = {\n      a: 'foo',\n      b: 'bar',\n      x: 11,\n      y: 19,\n    }\n    const conditions = {\n      a: equals('foo'),\n      b: equals('bar'),\n    }\n    const result = checkObjectWithSpec(conditions)(input)\n    result // $ExpectType boolean\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#checkObjectWithSpec)\n\n### compact\n\n```typescript\n\ncompact\u003cT\u003e(list: T[]): Array\u003cStrictNonNullable\u003cT\u003e\u003e\n```\n\nIt removes `null` and `undefined` members from list or object input.\n\n```javascript\nconst result = R.pipe(\n\t{\n\t\ta: [ undefined, '', 'a', 'b', 'c'],\n\t\tb: [1,2, null, 0, undefined, 3],\n\t\tc: { a: 1, b: 2, c: 0, d: undefined, e: null, f: false },\n\t},\n\tx =\u003e ({\n\t\ta: R.compact(x.a),\n\t\tb: R.compact(x.b),\n\t\tc: R.compact(x.c)\n\t})\n)\n// =\u003e { a: ['a', 'b', 'c'], b: [1, 2, 3], c: { a: 1, b: 2, c: 0, f: false } }\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.pipe(%0A%09%7B%0A%09%09a%3A%20%5B%20undefined%2C%20''%2C%20'a'%2C%20'b'%2C%20'c'%5D%2C%0A%09%09b%3A%20%5B1%2C2%2C%20null%2C%200%2C%20undefined%2C%203%5D%2C%0A%09%09c%3A%20%7B%20a%3A%201%2C%20b%3A%202%2C%20c%3A%200%2C%20d%3A%20undefined%2C%20e%3A%20null%2C%20f%3A%20false%20%7D%2C%0A%09%7D%2C%0A%09x%20%3D%3E%20(%7B%0A%09%09a%3A%20R.compact(x.a)%2C%0A%09%09b%3A%20R.compact(x.b)%2C%0A%09%09c%3A%20R.compact(x.c)%0A%09%7D)%0A)%0A%2F%2F%20%3D%3E%20%7B%20a%3A%20%5B'a'%2C%20'b'%2C%20'c'%5D%2C%20b%3A%20%5B1%2C%202%2C%203%5D%2C%20c%3A%20%7B%20a%3A%201%2C%20b%3A%202%2C%20c%3A%200%2C%20f%3A%20false%20%7D%20%7D\"\u003eTry this \u003cstrong\u003eR.compact\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ncompact\u003cT\u003e(list: T[]): Array\u003cStrictNonNullable\u003cT\u003e\u003e;\ncompact\u003cT extends object\u003e(record: T): {\n  [K in keyof T as Exclude\u003cT[K], null | undefined\u003e extends never\n    ? never\n    : K\n  ]: Exclude\u003cT[K], null | undefined\u003e\n};\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.compact\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { isArray } from './_internals/isArray.js'\nimport { reject } from './reject.js'\nimport { rejectObject } from './rejectObject.js'\n\nconst isNullOrUndefined = x =\u003e x === null || x === undefined\n\nexport function compact(input){\n\tif(isArray(input)){\n\t\treturn reject(isNullOrUndefined)(input)\n\t}\n\treturn rejectObject(isNullOrUndefined)(input)\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { compact } from './compact.js'\nimport { pipe } from './pipe.js'\n\ntest('happy', () =\u003e {\n  const result = pipe(\n\t\t{\n\t\t\ta: [ undefined, 'a', 'b', 'c'],\n\t\t\tb: [1,2, null, 0, undefined, 3],\n\t\t\tc: { a: 1, b: 2, c: 0, d: undefined, e: null, f: false },\n\t\t},\n\t\tx =\u003e ({\n\t\t\ta: compact(x.a),\n\t\t\tb: compact(x.b),\n\t\t\tc: compact(x.c)\n\t\t})\n\t)\n\texpect(result.a).toEqual(['a', 'b', 'c'])\n\texpect(result.b).toEqual([1,2,0,3])\n\texpect(result.c).toEqual({ a: 1, b: 2,c:0, f: false })\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { compact, pipe } from 'rambda'\n\nit('R.compact', () =\u003e {\n\t\tlet result = pipe(\n\t\t\t{\n\t\t\t\ta: [ undefined, '', 'a', 'b', 'c', null ],\n\t\t\t\tb: [1,2, null, 0, undefined, 3],\n\t\t\t\tc: { a: 1, b: 2, c: 0, d: undefined, e: null, f: false },\n\t\t\t},\n\t\t\tx =\u003e ({\n\t\t\t\ta: compact(x.a),\n\t\t\t\tb: compact(x.b),\n\t\t\t\tc: compact(x.c)\n\t\t\t})\n\t\t)\n\n\t\tresult.a // $ExpectType string[]\n\t\tresult.b // $ExpectType number[]\n\t\tresult.c // $ExpectType { a: number; b: number; c: number; f: boolean; }\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#compact)\n\n### complement\n\nIt returns `inverted` version of `origin` function that accept `input` as argument.\n\nThe return value of `inverted` is the negative boolean value of `origin(input)`.\n\n```javascript\nconst fn = x =\u003e x \u003e 5\nconst inverted = complement(fn)\n\nconst result = [\n  fn(7),\n  inverted(7)\n] =\u003e [ true, false ]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20fn%20%3D%20x%20%3D%3E%20x%20%3E%205%0Aconst%20inverted%20%3D%20complement(fn)%0A%0Aconst%20result%20%3D%20%5B%0A%20%20fn(7)%2C%0A%20%20inverted(7)%0A%5D%20%3D%3E%20%5B%20true%2C%20false%20%5D\"\u003eTry this \u003cstrong\u003eR.complement\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#complement)\n\n### concat\n\nIt returns a new string or array, which is the result of merging `x` and `y`.\n\n```javascript\nR.concat([1, 2])([3, 4]) // =\u003e [1, 2, 3, 4]\nR.concat('foo')('bar') // =\u003e 'foobar'\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?R.concat(%5B1%2C%202%5D)(%5B3%2C%204%5D)%20%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%2C%204%5D%0Aconst%20result%20%3D%20R.concat('foo')('bar')%20%2F%2F%20%3D%3E%20'foobar'\"\u003eTry this \u003cstrong\u003eR.concat\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#concat)\n\n### count\n\nIt counts how many times `predicate` function returns `true`, when supplied with iteration of `list`.\n\n```javascript\nconst list = [{a: 1}, 1, {a:2}]\nconst result = R.count(x =\u003e x.a !== undefined)(list)\n// =\u003e 2\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%7Ba%3A%201%7D%2C%201%2C%20%7Ba%3A2%7D%5D%0Aconst%20result%20%3D%20R.count(x%20%3D%3E%20x.a%20!%3D%3D%20undefined)(list)%0A%2F%2F%20%3D%3E%202\"\u003eTry this \u003cstrong\u003eR.count\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#count)\n\n### countBy\n\n```typescript\n\ncountBy\u003cT\u003e(fn: (x: T) =\u003e string | number): (list: T[]) =\u003e { [index: string]: number }\n```\n\nIt counts elements in a list after each instance of the input list is passed through `transformFn` function.\n\n```javascript\nconst list = [ 'a', 'A', 'b', 'B', 'c', 'C' ]\n\nconst result = countBy(x =\u003e x.toLowerCase())( list)\nconst expected = { a: 2, b: 2, c: 2 }\n// =\u003e `result` is equal to `expected`\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%20'a'%2C%20'A'%2C%20'b'%2C%20'B'%2C%20'c'%2C%20'C'%20%5D%0A%0Aconst%20result%20%3D%20countBy(x%20%3D%3E%20x.toLowerCase())(%20list)%0Aconst%20expected%20%3D%20%7B%20a%3A%202%2C%20b%3A%202%2C%20c%3A%202%20%7D%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60\"\u003eTry this \u003cstrong\u003eR.countBy\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ncountBy\u003cT\u003e(fn: (x: T) =\u003e string | number): (list: T[]) =\u003e { [index: string]: number };\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.countBy\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function countBy(fn) {\n  return list =\u003e {\n    const willReturn = {}\n\n    list.forEach(item =\u003e {\n      const key = fn(item)\n      if (!willReturn[key]) {\n        willReturn[key] = 1\n      } else {\n        willReturn[key]++\n      }\n    })\n\n    return willReturn\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { countBy } from './countBy.js'\n\nconst list = ['a', 'A', 'b', 'B', 'c', 'C']\n\ntest('happy', () =\u003e {\n  const result = countBy(x =\u003e x.toLowerCase())(list)\n  expect(result).toEqual({\n    a: 2,\n    b: 2,\n    c: 2,\n  })\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { countBy, pipe } from 'rambda'\n\nconst list = ['a', 'A', 'b', 'B', 'c', 'C']\n\nit('R.countBy', () =\u003e {\n  const result = pipe(\n    list,\n    countBy(x =\u003e x.toLowerCase()),\n  )\n  result.a // $ExpectType number\n  result.foo // $ExpectType number\n  result // $ExpectType { [index: string]: number; }\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#countBy)\n\n### createObjectFromKeys\n\n```typescript\n\ncreateObjectFromKeys\u003cconst K extends readonly PropertyKey[], V\u003e(\n\tfn: (key: K[number]) =\u003e V\n): (keys: K) =\u003e { [P in K[number]]: V }\n```\n\n```javascript\nconst result = R.createObjectFromKeys(\n\t(x, index) =\u003e `${x}-${index}`\n)(['a', 'b', 'c'])\n// =\u003e {a: 'a-0', b: 'b-1', c: 'c-2'}\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.createObjectFromKeys(%0A%09(x%2C%20index)%20%3D%3E%20%60%24%7Bx%7D-%24%7Bindex%7D%60%0A)(%5B'a'%2C%20'b'%2C%20'c'%5D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%20'a-0'%2C%20b%3A%20'b-1'%2C%20c%3A%20'c-2'%7D\"\u003eTry this \u003cstrong\u003eR.createObjectFromKeys\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ncreateObjectFromKeys\u003cconst K extends readonly PropertyKey[], V\u003e(\n\tfn: (key: K[number]) =\u003e V\n): (keys: K) =\u003e { [P in K[number]]: V };\ncreateObjectFromKeys\u003cconst K extends readonly PropertyKey[], V\u003e(\n\tfn: (key: K[number], index: number) =\u003e V\n): (keys: K) =\u003e { [P in K[number]]: V };\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.createObjectFromKeys\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function createObjectFromKeys(keys) {\n\treturn fn =\u003e {\n\t\tconst result = {}\n\t\tkeys.forEach((key, index) =\u003e {\n\t\t\tresult[key] = fn(key, index)\n\t\t})\n\n\t\treturn result\n\t}\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { createObjectFromKeys } from './createObjectFromKeys.js'\n\ntest('happy', () =\u003e {\n\tconst result = createObjectFromKeys(['a', 'b'])((key, index) =\u003e key.toUpperCase() + index)\n\tconst expected = { a: 'A0', b: 'B1' }\n\n\texpect(result).toEqual(expected)\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#createObjectFromKeys)\n\n### defaultTo\n\n```typescript\n\ndefaultTo\u003cT\u003e(defaultValue: T): (input: unknown) =\u003e T\n```\n\nIt returns `defaultValue`, if all of `inputArguments` are `undefined`, `null` or `NaN`.\n\nElse, it returns the first truthy `inputArguments` instance(from left to right).\n\n\u003e :boom: Typescript Note: Pass explicit type annotation when used with **R.pipe/R.compose** for better type inference\n\n```javascript\nR.defaultTo('foo')('bar') // =\u003e 'bar'\nR.defaultTo('foo'))(undefined) // =\u003e 'foo'\n\n// Important - emtpy string is not falsy value\nR.defaultTo('foo')('') // =\u003e 'foo'\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?R.defaultTo('foo')('bar')%20%2F%2F%20%3D%3E%20'bar'%0AR.defaultTo('foo'))(undefined)%20%2F%2F%20%3D%3E%20'foo'%0A%0A%2F%2F%20Important%20-%20emtpy%20string%20is%20not%20falsy%20value%0Aconst%20result%20%3D%20R.defaultTo('foo')('')%20%2F%2F%20%3D%3E%20'foo'\"\u003eTry this \u003cstrong\u003eR.defaultTo\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ndefaultTo\u003cT\u003e(defaultValue: T): (input: unknown) =\u003e T;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.defaultTo\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nfunction isFalsy(input) {\n  return input === undefined || input === null || Number.isNaN(input) === true\n}\n\nexport function defaultTo(defaultArgument, input) {\n  if (arguments.length === 1) {\n    return _input =\u003e defaultTo(defaultArgument, _input)\n  }\n\n  return isFalsy(input) ? defaultArgument : input\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { defaultTo } from './defaultTo.js'\n\ntest('with undefined', () =\u003e {\n  expect(defaultTo('foo')(undefined)).toBe('foo')\n})\n\ntest('with null', () =\u003e {\n  expect(defaultTo('foo')(null)).toBe('foo')\n})\n\ntest('with NaN', () =\u003e {\n  expect(defaultTo('foo')(Number.NaN)).toBe('foo')\n})\n\ntest('with empty string', () =\u003e {\n  expect(defaultTo('foo', '')).toBe('')\n})\n\ntest('with false', () =\u003e {\n  expect(defaultTo('foo', false)).toBeFalsy()\n})\n\ntest('when inputArgument passes initial check', () =\u003e {\n  expect(defaultTo('foo', 'bar')).toBe('bar')\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { defaultTo, pipe } from 'rambda'\n\ndescribe('R.defaultTo', () =\u003e {\n  it('happy', () =\u003e {\n    const result = pipe('bar' as unknown, defaultTo('foo'))\n\n    result // $ExpectType string\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#defaultTo)\n\n### descend\n\nHelper function to be used with `R.sort` to sort list in descending order.\n\n```javascript\nconst result = R.pipe(\n\t[{a: 1}, {a: 2}, {a: 0}],\n\tR.sort(R.descend(R.prop('a')))\n)\n// =\u003e [{a: 2}, {a: 1}, {a: 0}]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.pipe(%0A%09%5B%7Ba%3A%201%7D%2C%20%7Ba%3A%202%7D%2C%20%7Ba%3A%200%7D%5D%2C%0A%09R.sort(R.descend(R.prop('a')))%0A)%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A%202%7D%2C%20%7Ba%3A%201%7D%2C%20%7Ba%3A%200%7D%5D\"\u003eTry this \u003cstrong\u003eR.descend\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#descend)\n\n### drop\n\n```typescript\n\ndrop\u003cT\u003e(howMany: number): (list: T[]) =\u003e T[]\n```\n\nIt returns `howMany` items dropped from beginning of list.\n\n```javascript\nR.drop(2)(['foo', 'bar', 'baz']) // =\u003e ['baz']\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.drop(2)(%5B'foo'%2C%20'bar'%2C%20'baz'%5D)%20%2F%2F%20%3D%3E%20%5B'baz'%5D\"\u003eTry this \u003cstrong\u003eR.drop\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ndrop\u003cT\u003e(howMany: number): (list: T[]) =\u003e T[];\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.drop\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function drop(howManyToDrop, listOrString) {\n  if (arguments.length === 1) {\n    return _list =\u003e drop(howManyToDrop, _list)\n  }\n\n  return listOrString.slice(howManyToDrop \u003e 0 ? howManyToDrop : 0)\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport assert from 'node:assert'\n\nimport { drop } from './drop.js'\n\ntest('with array', () =\u003e {\n  expect(drop(2)(['foo', 'bar', 'baz'])).toEqual(['baz'])\n  expect(drop(3, ['foo', 'bar', 'baz'])).toEqual([])\n  expect(drop(4, ['foo', 'bar', 'baz'])).toEqual([])\n})\n\ntest('with string', () =\u003e {\n  expect(drop(3, 'rambda')).toBe('bda')\n})\n\ntest('with non-positive count', () =\u003e {\n  expect(drop(0, [1, 2, 3])).toEqual([1, 2, 3])\n  expect(drop(-1, [1, 2, 3])).toEqual([1, 2, 3])\n  expect(drop(Number.NEGATIVE_INFINITY, [1, 2, 3])).toEqual([1, 2, 3])\n})\n\ntest('should return copy', () =\u003e {\n  const xs = [1, 2, 3]\n\n  assert.notStrictEqual(drop(0, xs), xs)\n  assert.notStrictEqual(drop(-1, xs), xs)\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { drop, pipe } from 'rambda'\n\nit('R.drop', () =\u003e {\n  const result = pipe([1, 2, 3, 4], drop(2))\n  result // $ExpectType number[]\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#drop)\n\n### dropLast\n\n```typescript\n\ndropLast\u003cT\u003e(howMany: number): (list: T[]) =\u003e T[]\n```\n\nIt returns `howMany` items dropped from the end of list.\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ndropLast\u003cT\u003e(howMany: number): (list: T[]) =\u003e T[];\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.dropLast\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function dropLast(numberItems) {\n  return list =\u003e (numberItems \u003e 0 ? list.slice(0, -numberItems) : list.slice())\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { dropLast } from './dropLast.js'\n\ntest('with array', () =\u003e {\n  expect(dropLast(2)(['foo', 'bar', 'baz'])).toEqual(['foo'])\n  expect(dropLast(3)(['foo', 'bar', 'baz'])).toEqual([])\n  expect(dropLast(4)(['foo', 'bar', 'baz'])).toEqual([])\n})\n\ntest('with non-positive count', () =\u003e {\n  expect(dropLast(0)([1, 2, 3])).toEqual([1, 2, 3])\n  expect(dropLast(-1)([1, 2, 3])).toEqual([1, 2, 3])\n  expect(dropLast(Number.NEGATIVE_INFINITY)([1, 2, 3])).toEqual([1, 2, 3])\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#dropLast)\n\n### dropLastWhile\n\n```javascript\nconst list = [1, 2, 3, 4, 5];\nconst predicate = x =\u003e x \u003e= 3\n\nconst result = dropLastWhile(predicate)(list);\n// =\u003e [1, 2]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%3B%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%3D%203%0A%0Aconst%20result%20%3D%20dropLastWhile(predicate)(list)%3B%0A%2F%2F%20%3D%3E%20%5B1%2C%202%5D\"\u003eTry this \u003cstrong\u003eR.dropLastWhile\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#dropLastWhile)\n\n### dropRepeatsBy\n\n```javascript\nconst result = R.dropRepeatsBy(\n  Math.abs,\n  [1, -1, 2, 3, -3]\n)\n// =\u003e [1, 2, 3]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.dropRepeatsBy(%0A%20%20Math.abs%2C%0A%20%20%5B1%2C%20-1%2C%202%2C%203%2C%20-3%5D%0A)%0A%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%5D\"\u003eTry this \u003cstrong\u003eR.dropRepeatsBy\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#dropRepeatsBy)\n\n### dropRepeatsWith\n\n```javascript\nconst list = [{a:1,b:2}, {a:1,b:3}, {a:2, b:4}]\nconst result = R.dropRepeatsWith(R.prop('a'))(list)\n\n// =\u003e [{a:1,b:2}, {a:2, b:4}]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%7Ba%3A1%2Cb%3A2%7D%2C%20%7Ba%3A1%2Cb%3A3%7D%2C%20%7Ba%3A2%2C%20b%3A4%7D%5D%0Aconst%20result%20%3D%20R.dropRepeatsWith(R.prop('a'))(list)%0A%0A%2F%2F%20%3D%3E%20%5B%7Ba%3A1%2Cb%3A2%7D%2C%20%7Ba%3A2%2C%20b%3A4%7D%5D\"\u003eTry this \u003cstrong\u003eR.dropRepeatsWith\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#dropRepeatsWith)\n\n### dropWhile\n\n```javascript\nconst list = [1, 2, 3, 4]\nconst predicate = x =\u003e x \u003c 3\nconst result = R.dropWhile(predicate)(list)\n// =\u003e [3, 4]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%204%5D%0Aconst%20predicate%20%3D%20x%20%3D%3E%20x%20%3C%203%0Aconst%20result%20%3D%20R.dropWhile(predicate)(list)%0A%2F%2F%20%3D%3E%20%5B3%2C%204%5D\"\u003eTry this \u003cstrong\u003eR.dropWhile\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#dropWhile)\n\n### eqBy\n\n```javascript\nconst result = R.eqBy(Math.abs, 5)(-5)\n// =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.eqBy(Math.abs%2C%205)(-5)%0A%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.eqBy\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#eqBy)\n\n### eqProps\n\nIt returns `true` if property `prop` in `obj1` is equal to property `prop` in `obj2` according to `R.equals`.\n\n```javascript\nconst obj1 = {a: 1, b:2}\nconst obj2 = {a: 1, b:3}\nconst result = R.eqProps('a', obj1)(obj2)\n// =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20obj1%20%3D%20%7Ba%3A%201%2C%20b%3A2%7D%0Aconst%20obj2%20%3D%20%7Ba%3A%201%2C%20b%3A3%7D%0Aconst%20result%20%3D%20R.eqProps('a'%2C%20obj1)(obj2)%0A%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.eqProps\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#eqProps)\n\n### equals\n\n```typescript\n\nequals\u003cT\u003e(x: T, y: T): boolean\n```\n\nIt deeply compares `x` and `y` and returns `true` if they are equal.\n\n\u003e :boom: It doesn't handle cyclical data structures and functions\n\n```javascript\nR.equals(\n  [1, {a:2}, [{b: 3}]],\n  [1, {a:2}, [{b: 3}]]\n) // =\u003e true\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?R.equals(%0A%20%20%5B1%2C%20%7Ba%3A2%7D%2C%20%5B%7Bb%3A%203%7D%5D%5D%2C%0A%20%20%5B1%2C%20%7Ba%3A2%7D%2C%20%5B%7Bb%3A%203%7D%5D%5D%0Aconst%20result%20%3D%20)%20%2F%2F%20%3D%3E%20true\"\u003eTry this \u003cstrong\u003eR.equals\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nequals\u003cT\u003e(x: T, y: T): boolean;\nequals\u003cT\u003e(x: T): (y: T) =\u003e boolean;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.equals\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { isArray } from './_internals/isArray.js'\nimport { type } from './type.js'\n\nexport function _lastIndexOf(valueToFind, list) {\n  if (!isArray(list)) {\n    throw new Error(`Cannot read property 'indexOf' of ${list}`)\n  }\n\n  const typeOfValue = type(valueToFind)\n  if (!['Array', 'NaN', 'Object', 'RegExp'].includes(typeOfValue)) {\n    return list.lastIndexOf(valueToFind)\n  }\n\n  const { length } = list\n  let index = length\n  let foundIndex = -1\n\n  while (--index \u003e -1 \u0026\u0026 foundIndex === -1) {\n    if (equalsFn(list[index], valueToFind)) {\n      foundIndex = index\n    }\n  }\n\n  return foundIndex\n}\n\nexport function _indexOf(valueToFind, list) {\n  if (!isArray(list)) {\n    throw new Error(`Cannot read property 'indexOf' of ${list}`)\n  }\n\n  const typeOfValue = type(valueToFind)\n  if (!['Array', 'NaN', 'Object', 'RegExp'].includes(typeOfValue)) {\n    return list.indexOf(valueToFind)\n  }\n\n  let index = -1\n  let foundIndex = -1\n  const { length } = list\n\n  while (++index \u003c length \u0026\u0026 foundIndex === -1) {\n    if (equalsFn(list[index], valueToFind)) {\n      foundIndex = index\n    }\n  }\n\n  return foundIndex\n}\n\nfunction _arrayFromIterator(iter) {\n  const list = []\n  let next\n  while (!(next = iter.next()).done) {\n    list.push(next.value)\n  }\n\n  return list\n}\n\nfunction _compareSets(a, b) {\n  if (a.size !== b.size) {\n    return false\n  }\n\n  const aList = _arrayFromIterator(a.values())\n  const bList = _arrayFromIterator(b.values())\n\n  const filtered = aList.filter(aInstance =\u003e _indexOf(aInstance, bList) === -1)\n\n  return filtered.length === 0\n}\n\nfunction compareErrors(a, b) {\n  if (a.message !== b.message) {\n    return false\n  }\n  if (a.toString !== b.toString) {\n    return false\n  }\n\n  return a.toString() === b.toString()\n}\n\nfunction parseDate(maybeDate) {\n  if (!maybeDate.toDateString) {\n    return [false]\n  }\n\n  return [true, maybeDate.getTime()]\n}\n\nfunction parseRegex(maybeRegex) {\n  if (maybeRegex.constructor !== RegExp) {\n    return [false]\n  }\n\n  return [true, maybeRegex.toString()]\n}\n\nexport function equalsFn(a, b) {\n  if (Object.is(a, b)) {\n    return true\n  }\n\n  const aType = type(a)\n\n  if (aType !== type(b)) {\n    return false\n  }\n  if (aType === 'Function') {\n    return a.name === undefined ? false : a.name === b.name\n  }\n\n  if (['NaN', 'Null', 'Undefined'].includes(aType)) {\n    return true\n  }\n\n  if (['BigInt', 'Number'].includes(aType)) {\n    if (Object.is(-0, a) !== Object.is(-0, b)) {\n      return false\n    }\n\n    return a.toString() === b.toString()\n  }\n\n  if (['Boolean', 'String'].includes(aType)) {\n    return a.toString() === b.toString()\n  }\n\n  if (aType === 'Array') {\n    const aClone = Array.from(a)\n    const bClone = Array.from(b)\n\n    if (aClone.toString() !== bClone.toString()) {\n      return false\n    }\n\n    let loopArrayFlag = true\n    aClone.forEach((aCloneInstance, aCloneIndex) =\u003e {\n      if (loopArrayFlag) {\n        if (\n          aCloneInstance !== bClone[aCloneIndex] \u0026\u0026\n          !equalsFn(aCloneInstance, bClone[aCloneIndex])\n        ) {\n          loopArrayFlag = false\n        }\n      }\n    })\n\n    return loopArrayFlag\n  }\n\n  const aRegex = parseRegex(a)\n  const bRegex = parseRegex(b)\n\n  if (aRegex[0]) {\n    return bRegex[0] ? aRegex[1] === bRegex[1] : false\n  }\n  if (bRegex[0]) {\n    return false\n  }\n\n  const aDate = parseDate(a)\n  const bDate = parseDate(b)\n\n  if (aDate[0]) {\n    return bDate[0] ? aDate[1] === bDate[1] : false\n  }\n  if (bDate[0]) {\n    return false\n  }\n\n  if (a instanceof Error) {\n    if (!(b instanceof Error)) {\n      return false\n    }\n\n    return compareErrors(a, b)\n  }\n\n  if (aType === 'Set') {\n    return _compareSets(a, b)\n  }\n\n  if (aType === 'Object') {\n    const aKeys = Object.keys(a)\n\n    if (aKeys.length !== Object.keys(b).length) {\n      return false\n    }\n\n    let loopObjectFlag = true\n    aKeys.forEach(aKeyInstance =\u003e {\n      if (loopObjectFlag) {\n        const aValue = a[aKeyInstance]\n        const bValue = b[aKeyInstance]\n\n        if (aValue !== bValue \u0026\u0026 !equalsFn(aValue, bValue)) {\n          loopObjectFlag = false\n        }\n      }\n    })\n\n    return loopObjectFlag\n  }\n\n  return false\n}\nexport function equals(a) {\n  return b =\u003e equalsFn(a, b)\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { equalsFn } from './equals.js'\n\ntest('compare functions', () =\u003e {\n  function foo() {}\n  function bar() {}\n  const baz = () =\u003e {}\n\n  const expectTrue = equalsFn(foo, foo)\n  const expectFalseFirst = equalsFn(foo, bar)\n  const expectFalseSecond = equalsFn(foo, baz)\n\n  expect(expectTrue).toBeTruthy()\n  expect(expectFalseFirst).toBeFalsy()\n  expect(expectFalseSecond).toBeFalsy()\n})\n\ntest('with array of objects', () =\u003e {\n  const list1 = [{ a: 1 }, [{ b: 2 }]]\n  const list2 = [{ a: 1 }, [{ b: 2 }]]\n  const list3 = [{ a: 1 }, [{ b: 3 }]]\n\n  expect(equalsFn(list1, list2)).toBeTruthy()\n  expect(equalsFn(list1, list3)).toBeFalsy()\n})\n\ntest('with regex', () =\u003e {\n  expect(equalsFn(/s/, /s/)).toBeTruthy()\n  expect(equalsFn(/s/, /d/)).toBeFalsy()\n  expect(equalsFn(/a/gi, /a/gi)).toBeTruthy()\n  expect(equalsFn(/a/gim, /a/gim)).toBeTruthy()\n  expect(equalsFn(/a/gi, /a/i)).toBeFalsy()\n})\n\ntest('not a number', () =\u003e {\n  expect(equalsFn([Number.NaN], [Number.NaN])).toBeTruthy()\n})\n\ntest('new number', () =\u003e {\n  expect(equalsFn(new Number(0), new Number(0))).toBeTruthy()\n  expect(equalsFn(new Number(0), new Number(1))).toBeFalsy()\n  expect(equalsFn(new Number(1), new Number(0))).toBeFalsy()\n})\n\ntest('new string', () =\u003e {\n  expect(equalsFn(new String(''), new String(''))).toBeTruthy()\n  expect(equalsFn(new String(''), new String('x'))).toBeFalsy()\n  expect(equalsFn(new String('x'), new String(''))).toBeFalsy()\n  expect(equalsFn(new String('foo'), new String('foo'))).toBeTruthy()\n  expect(equalsFn(new String('foo'), new String('bar'))).toBeFalsy()\n  expect(equalsFn(new String('bar'), new String('foo'))).toBeFalsy()\n})\n\ntest('new Boolean', () =\u003e {\n  expect(equalsFn(new Boolean(true), new Boolean(true))).toBeTruthy()\n  expect(equalsFn(new Boolean(false), new Boolean(false))).toBeTruthy()\n  expect(equalsFn(new Boolean(true), new Boolean(false))).toBeFalsy()\n  expect(equalsFn(new Boolean(false), new Boolean(true))).toBeFalsy()\n})\n\ntest('new Error', () =\u003e {\n  expect(equalsFn(new Error('XXX'), {})).toBeFalsy()\n  expect(equalsFn(new Error('XXX'), new TypeError('XXX'))).toBeFalsy()\n  expect(equalsFn(new Error('XXX'), new Error('YYY'))).toBeFalsy()\n  expect(equalsFn(new Error('XXX'), new Error('XXX'))).toBeTruthy()\n  expect(equalsFn(new Error('XXX'), new TypeError('YYY'))).toBeFalsy()\n  expect(equalsFn(new Error('XXX'), new Error('XXX'))).toBeTruthy()\n})\n\ntest('with dates', () =\u003e {\n  expect(equalsFn(new Date(0), new Date(0))).toBeTruthy()\n  expect(equalsFn(new Date(1), new Date(1))).toBeTruthy()\n  expect(equalsFn(new Date(0), new Date(1))).toBeFalsy()\n  expect(equalsFn(new Date(1), new Date(0))).toBeFalsy()\n  expect(equalsFn(new Date(0), {})).toBeFalsy()\n  expect(equalsFn({}, new Date(0))).toBeFalsy()\n})\n\ntest('ramda spec', () =\u003e {\n  expect(equalsFn({}, {})).toBeTruthy()\n\n  expect(\n    equalsFn(\n      {\n        a: 1,\n        b: 2,\n      },\n      {\n        a: 1,\n        b: 2,\n      },\n    ),\n  ).toBeTruthy()\n\n  expect(\n    equalsFn(\n      {\n        a: 2,\n        b: 3,\n      },\n      {\n        a: 2,\n        b: 3,\n      },\n    ),\n  ).toBeTruthy()\n\n  expect(\n    equalsFn(\n      {\n        a: 2,\n        b: 3,\n      },\n      {\n        a: 3,\n        b: 3,\n      },\n    ),\n  ).toBeFalsy()\n\n  expect(\n    equalsFn(\n      {\n        a: 2,\n        b: 3,\n        c: 1,\n      },\n      {\n        a: 2,\n        b: 3,\n      },\n    ),\n  ).toBeFalsy()\n})\n\ntest('works with boolean tuple', () =\u003e {\n  expect(equalsFn([true, false], [true, false])).toBeTruthy()\n  expect(equalsFn([true, false], [true, true])).toBeFalsy()\n})\n\ntest('works with equal objects within array', () =\u003e {\n  const objFirst = {\n    a: {\n      b: 1,\n      c: 2,\n      d: [1],\n    },\n  }\n  const objSecond = {\n    a: {\n      b: 1,\n      c: 2,\n      d: [1],\n    },\n  }\n\n  const x = [1, 2, objFirst, null, '', []]\n  const y = [1, 2, objSecond, null, '', []]\n  expect(equalsFn(x, y)).toBeTruthy()\n})\n\ntest('works with different objects within array', () =\u003e {\n  const objFirst = { a: { b: 1 } }\n  const objSecond = { a: { b: 2 } }\n\n  const x = [1, 2, objFirst, null, '', []]\n  const y = [1, 2, objSecond, null, '', []]\n  expect(equalsFn(x, y)).toBeFalsy()\n})\n\ntest('works with undefined as second argument', () =\u003e {\n  expect(equalsFn(1, undefined)).toBeFalsy()\n\n  expect(equalsFn(undefined, undefined)).toBeTruthy()\n})\n\ntest('compare sets', () =\u003e {\n  const toCompareDifferent = new Set([{ a: 1 }, { a: 2 }])\n  const toCompareSame = new Set([{ a: 1 }, { a: 2 }, { a: 1 }])\n  const testSet = new Set([{ a: 1 }, { a: 2 }, { a: 1 }])\n  expect(equalsFn(toCompareSame, testSet)).toBeTruthy()\n  expect(equalsFn(toCompareDifferent, testSet)).toBeFalsy()\n})\n\ntest('compare simple sets', () =\u003e {\n  const testSet = new Set(['2', '3', '3', '2', '1'])\n  expect(equalsFn(new Set(['3', '2', '1']), testSet)).toBeTruthy()\n  expect(equalsFn(new Set(['3', '2', '0']), testSet)).toBeFalsy()\n})\n\ntest('various examples', () =\u003e {\n  expect(equalsFn([1, 2, 3], [1, 2, 3])).toBeTruthy()\n  expect(equalsFn([1, 2, 3], [1, 2])).toBeFalsy()\n  expect(equalsFn({}, {})).toBeTruthy()\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { equals } from 'rambda'\n\ndescribe('R.equals', () =\u003e {\n  it('happy', () =\u003e {\n    const result = equals(4, 1)\n    result // $ExpectType boolean\n  })\n  it('with object', () =\u003e {\n    const foo = { a: 1 }\n    const bar = { a: 2 }\n    const result = equals(foo, bar)\n    result // $ExpectType boolean\n  })\n  it('curried', () =\u003e {\n    const result = equals(4)(1)\n\n    result // $ExpectType boolean\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#equals)\n\n### evolve\n\n```typescript\n\nevolve\u003cT\u003e(rules: {\n\t[K in keyof T]?: (x: T[K]) =\u003e T[K]\n}): (obj: T) =\u003e T\n```\n\nIt takes object of functions as set of rules. These `rules` are applied to the `iterable` input to produce the result.\nIt doesn't support nested rules, i.e rules are only one level deep.\n\n```javascript\nconst input = {\n\tfoo: 2,\n\tbaz: 'baz',\n}\nconst result = R.pipe(\n\tinput, \n\tevolve({\n\t\tfoo: x =\u003e x + 1,\n\t})\n)\n// =\u003e result is { foo: 3, baz: 'baz' }\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20input%20%3D%20%7B%0A%09foo%3A%202%2C%0A%09baz%3A%20'baz'%2C%0A%7D%0Aconst%20result%20%3D%20R.pipe(%0A%09input%2C%20%0A%09evolve(%7B%0A%09%09foo%3A%20x%20%3D%3E%20x%20%2B%201%2C%0A%09%7D)%0A)%0A%2F%2F%20%3D%3E%20result%20is%20%7B%20foo%3A%203%2C%20baz%3A%20'baz'%20%7D\"\u003eTry this \u003cstrong\u003eR.evolve\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nevolve\u003cT\u003e(rules: {\n\t[K in keyof T]?: (x: T[K]) =\u003e T[K]\n}): (obj: T) =\u003e T;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.evolve\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { mapObject } from './mapObject.js'\nimport { type } from './type.js'\n\nexport function evolve(rules) {\n  return mapObject((x, prop) =\u003e type(rules[prop]) === 'Function' ? rules[prop](x): x)\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { evolve } from './evolve.js'\n\ntest('happy', () =\u003e {\n  const rules = {\n    foo: x =\u003e x + 1,\n  }\n  const input = {\n    a: 1,\n    foo: 2,\n\t\tnested: { bar: { z: 3 } },\n  }\n  const result = evolve(rules)(input)\n  expect(result).toEqual({\n    a: 1,\n    foo: 3,\n\t\tnested: { bar: { z: 3 } },\n  })\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport {  evolve, pipe } from 'rambda'\n\nit('R.evolve', () =\u003e {\n  const input = {\n\t\tbaz: 1,\n    foo: 2,\n    nested: {\n      a: 1,\n      bar: 3,\n    },\n  }\n  const result = pipe(input, \n\t\tevolve({\n\t\t\tfoo: x =\u003e x + 1,\n\t\t})\n\t)\n  result.foo // $ExpectType number\n  result.baz // $ExpectType number\n  result.nested.a // $ExpectType number\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#evolve)\n\n### excludes\n\nOpposite of `R.includes`\n\n`R.equals` is used to determine equality.\n\n```javascript\nconst result = [\n  R.excludes('ar')('foo'),\n  R.excludes({a: 2})([{a: 1}])\n]\n// =\u003e [true, true ]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.excludes('ar')('foo')%2C%0A%20%20R.excludes(%7Ba%3A%202%7D)(%5B%7Ba%3A%201%7D%5D)%0A%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20true%20%5D\"\u003eTry this \u003cstrong\u003eR.excludes\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#excludes)\n\n### filter\n\n```typescript\n\nfilter\u003cT, S extends T\u003e(\n  predicate: (value: T) =\u003e value is S,\n): (list: T[]) =\u003e S[]\n```\n\nIt filters list or object `input` using a `predicate` function.\n\n```javascript\nconst predicate = x =\u003e x \u003e 1\nconst list = [1, 2, 3]\nconst result = R.filter(predicate)(list)\n// =\u003e [2, 3]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20x%20%3E%201%0Aconst%20list%20%3D%20%5B1%2C%202%2C%203%5D%0Aconst%20result%20%3D%20R.filter(predicate)(list)%0A%2F%2F%20%3D%3E%20%5B2%2C%203%5D\"\u003eTry this \u003cstrong\u003eR.filter\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfilter\u003cT, S extends T\u003e(\n  predicate: (value: T) =\u003e value is S,\n): (list: T[]) =\u003e S[];\nfilter\u003cT\u003e(\n\tpredicate: BooleanConstructor,\n): (list: readonly T[]) =\u003e StrictNonNullable\u003cT\u003e[];\nfilter\u003cT\u003e(\n\tpredicate: BooleanConstructor,\n): (list: T[]) =\u003e StrictNonNullable\u003cT\u003e[];\nfilter\u003cT\u003e(\n\tpredicate: (value: T) =\u003e boolean,\n): (list: T[]) =\u003e T[];\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.filter\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function filter(predicate) {\n  return list =\u003e {\n    if (!list) {\n      throw new Error('Incorrect iterable input')\n    }\n    let index = 0\n    const len = list.length\n    const willReturn = []\n\n    while (index \u003c len) {\n      if (predicate(list[index], index)) {\n        willReturn.push(list[index])\n      }\n\n      index++\n    }\n\n    return willReturn\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { filter } from './filter.js'\n\ntest('happy', () =\u003e {\n  const isEven = n =\u003e n % 2 === 0\n\n  expect(filter(isEven)([1, 2, 3, 4])).toEqual([2, 4])\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { filter, mergeTypes, pipe } from 'rambda'\n\nconst list = [1, 2, 3]\n\ndescribe('R.filter with array', () =\u003e {\n  it('within pipe', () =\u003e {\n    const result = pipe(\n      list,\n      filter(x =\u003e {\n        x // $ExpectType number\n        return x \u003e 1\n      }),\n    )\n    result // $ExpectType number[]\n  })\n  it('narrowing type', () =\u003e {\n    interface Foo {\n      a: number\n    }\n    interface Bar extends Foo {\n      b: string\n    }\n\t\ttype T = Foo | Bar\n    const testList: T[]= [{ a: 1 }, { a: 2 }, { a: 3 }] \n    const filterBar = (x: T): x is Bar =\u003e {\n      return typeof (x as Bar).b === 'string'\n    }\n    const result = pipe(\n      testList,\n      filter(filterBar),\n    )\n    result // $ExpectType Bar[]\n  })\n  it('narrowing type - readonly', () =\u003e {\n    interface Foo {\n      a: number\n    }\n    interface Bar extends Foo {\n      b: string\n    }\n\t\ttype T = Foo | Bar\n    const testList: T[]= [{ a: 1 }, { a: 2 }, { a: 3 }] as const\n    const filterBar = (x: T): x is Bar =\u003e {\n      return typeof (x as Bar).b === 'string'\n    }\n    const result = pipe(\n      testList,\n      filter(filterBar),\n    )\n    result // $ExpectType Bar[]\n  })\n  it('filtering NonNullable', () =\u003e {\n    const testList = [1, 2, null, undefined, 3]\n    const result = pipe(testList, filter(Boolean))\n    result // $ExpectType number[]\n  })\n  it('filtering NonNullable - readonly', () =\u003e {\n    const testList = [1, 2, null, undefined, 3] as const\n    const result = pipe(testList, filter(Boolean))\n    result.includes(1)\n    // @ts-expect-error\n    result.includes(4)\n    // @ts-expect-error\n    result.includes(undefined) \n    // @ts-expect-error\n    result.includes(null)\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#filter)\n\n### filterObject\n\n```typescript\n\nfilterObject\u003cT extends object\u003e(\n  valueMapper: (\n    value: EnumerableStringKeyedValueOf\u003cT\u003e,\n    key: EnumerableStringKeyOf\u003cT\u003e,\n    data: T,\n  ) =\u003e boolean,\n): \u003cU extends T\u003e(data: T) =\u003e U\n```\n\nIt loops over each property of `obj` and returns a new object with only those properties that satisfy the `predicate`.\n\n```javascript\nconst result = R.filterObject(\n\t(val, prop) =\u003e prop === 'a' || val \u003e 1\n)({a: 1, b: 2, c:3})\n// =\u003e {a: 1, c: 3}\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.filterObject(%0A%09(val%2C%20prop)%20%3D%3E%20prop%20%3D%3D%3D%20'a'%20%7C%7C%20val%20%3E%201%0A)(%7Ba%3A%201%2C%20b%3A%202%2C%20c%3A3%7D)%0A%2F%2F%20%3D%3E%20%7Ba%3A%201%2C%20c%3A%203%7D\"\u003eTry this \u003cstrong\u003eR.filterObject\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfilterObject\u003cT extends object\u003e(\n  valueMapper: (\n    value: EnumerableStringKeyedValueOf\u003cT\u003e,\n    key: EnumerableStringKeyOf\u003cT\u003e,\n    data: T,\n  ) =\u003e boolean,\n): \u003cU extends T\u003e(data: T) =\u003e U;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.filterObject\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function filterObject(predicate) {\n  return obj =\u003e {\n    const willReturn = {}\n\n    for (const prop in obj) {\n      if (predicate(obj[prop], prop, obj)) {\n        willReturn[prop] = obj[prop]\n      }\n    }\n\n    return willReturn\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { pipe } from './pipe.js'\nimport { filterObject } from './filterObject.js'\n\ntest('happy', () =\u003e {\n\tlet testInput = { a: 1, b: 2, c: 3 }\n  const result = pipe(\n\t\ttestInput,\n\t\tfilterObject((x, prop, obj) =\u003e {\n\t\t\texpect(prop).toBeOneOf(['a', 'b', 'c'])\n\t\t\texpect(obj).toBe(testInput)\n\t\t\treturn x \u003e 1\n\t\t})\n\t)\n\texpect(result).toEqual({ b: 2, c: 3 })\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { filterObject, pipe } from 'rambda'\n\ndescribe('R.filterObject', () =\u003e {\n  it('require explicit type', () =\u003e {\n    const result = pipe(\n      { a: 1, b: 2 },\n      filterObject\u003c{ b: number }\u003e(a =\u003e {\n        a // $ExpectType number\n        return a \u003e 1\n      }),\n    )\n    result.b // $ExpectType number\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#filterObject)\n\n### find\n\n```typescript\n\nfind\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e T | undefined\n```\n\nIt returns the first element of `list` that satisfy the `predicate`.\n\nIf there is no such element, it returns `undefined`.\n\n```javascript\nconst predicate = x =\u003e R.type(x.foo) === 'Number'\nconst list = [{foo: 'bar'}, {foo: 1}]\n\nconst result = R.find(predicate)(list)\n// =\u003e {foo: 1}\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%20'bar'%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.find(predicate)(list)%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%201%7D\"\u003eTry this \u003cstrong\u003eR.find\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfind\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e T | undefined;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.find\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function find(predicate) {\n  return list =\u003e {\n    let index = 0\n    const len = list.length\n\n    while (index \u003c len) {\n      const x = list[index]\n      if (predicate(x)) {\n        return x\n      }\n\n      index++\n    }\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { find } from './find.js'\nimport { propEq } from './propEq.js'\n\nconst list = [{ a: 1 }, { a: 2 }, { a: 3 }]\n\ntest('happy', () =\u003e {\n  const fn = propEq(2, 'a')\n  expect(find(fn)(list)).toEqual({ a: 2 })\n})\n\ntest('nothing is found', () =\u003e {\n  const fn = propEq(4, 'a')\n  expect(find(fn)(list)).toBeUndefined()\n})\n\ntest('with empty list', () =\u003e {\n  expect(find(() =\u003e true)([])).toBeUndefined()\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { find, pipe } from 'rambda'\n\nconst list = [1, 2, 3]\n\ndescribe('R.find', () =\u003e {\n  it('happy', () =\u003e {\n    const predicate = (x: number) =\u003e x \u003e 2\n    const result = pipe(list, find(predicate))\n    result // $ExpectType number | undefined\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#find)\n\n### findIndex\n\n```typescript\n\nfindIndex\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e number\n```\n\nIt returns the index of the first element of `list` satisfying the `predicate` function.\n\nIf there is no such element, then `-1` is returned.\n\n```javascript\nconst predicate = x =\u003e R.type(x.foo) === 'Number'\nconst list = [{foo: 'bar'}, {foo: 1}]\n\nconst result = R.findIndex(predicate)(list)\n// =\u003e 1\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%20'bar'%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.findIndex(predicate)(list)%0A%2F%2F%20%3D%3E%201\"\u003eTry this \u003cstrong\u003eR.findIndex\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfindIndex\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e number;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.findIndex\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function findIndex(predicate) {\n  return list =\u003e {\n    const len = list.length\n    let index = -1\n\n    while (++index \u003c len) {\n      if (predicate(list[index])) {\n        return index\n      }\n    }\n\n    return -1\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { findIndex } from './findIndex.js'\nimport { propEq } from './propEq.js'\n\nconst list = [{ a: 1 }, { a: 2 }, { a: 3 }]\n\ntest('happy', () =\u003e {\n  expect(findIndex(propEq(2, 'a'))(list)).toBe(1)\n  expect(findIndex(propEq(1, 'a'))(list)).toBe(0)\n  expect(findIndex(propEq(4, 'a'))(list)).toBe(-1)\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { findIndex, pipe } from 'rambda'\n\nconst list = [1, 2, 3]\n\nit('R.findIndex', () =\u003e {\n  const result = pipe(\n    list,\n    findIndex(x =\u003e x \u003e 2),\n  )\n  result // $ExpectType number\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#findIndex)\n\n### findLast\n\n```typescript\n\nfindLast\u003cT\u003e(fn: (x: T) =\u003e boolean): (list: T[]) =\u003e T | undefined\n```\n\nIt returns the last element of `list` satisfying the `predicate` function.\n\nIf there is no such element, then `undefined` is returned.\n\n```javascript\nconst predicate = x =\u003e R.type(x.foo) === 'Number'\nconst list = [{foo: 0}, {foo: 1}]\n\nconst result = R.findLast(predicate)(list)\n// =\u003e {foo: 1}\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%200%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.findLast(predicate)(list)%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%201%7D\"\u003eTry this \u003cstrong\u003eR.findLast\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfindLast\u003cT\u003e(fn: (x: T) =\u003e boolean): (list: T[]) =\u003e T | undefined;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.findLast\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function findLast(predicate) {\n  return list =\u003e {\n    let index = list.length\n\n    while (--index \u003e= 0) {\n      if (predicate(list[index])) {\n        return list[index]\n      }\n    }\n\n    return undefined\n  }\n}\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#findLast)\n\n### findLastIndex\n\n```typescript\n\nfindLastIndex\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e number\n```\n\nIt returns the index of the last element of `list` satisfying the `predicate` function.\n\nIf there is no such element, then `-1` is returned.\n\n```javascript\nconst predicate = x =\u003e R.type(x.foo) === 'Number'\nconst list = [{foo: 0}, {foo: 1}]\n\nconst result = R.findLastIndex(predicate)(list)\n// =\u003e 1\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%200%7D%2C%20%7Bfoo%3A%201%7D%5D%0A%0Aconst%20result%20%3D%20R.findLastIndex(predicate)(list)%0A%2F%2F%20%3D%3E%201\"\u003eTry this \u003cstrong\u003eR.findLastIndex\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfindLastIndex\u003cT\u003e(predicate: (x: T) =\u003e boolean): (list: T[]) =\u003e number;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.findLastIndex\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function findLastIndex(fn) {\n  return list =\u003e {\n    let index = list.length\n\n    while (--index \u003e= 0) {\n      if (fn(list[index])) {\n        return index\n      }\n    }\n\n    return -1\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { findLastIndex } from './findLastIndex.js'\n\ntest('happy', () =\u003e {\n  const result = findLastIndex(x =\u003e x \u003e 1)([1, 1, 1, 2, 3, 4, 1])\n  expect(result).toBe(5)\n  expect(findLastIndex(x =\u003e x === 0)([0, 1, 1, 2, 3, 4, 1])).toBe(0)\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { findLastIndex, pipe } from 'rambda'\n\nconst list = [1, 2, 3]\n\ndescribe('R.findLastIndex', () =\u003e {\n  it('happy', () =\u003e {\n    const predicate = (x: number) =\u003e x \u003e 2\n    const result = pipe(list, findLastIndex(predicate))\n    result // $ExpectType number\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#findLastIndex)\n\n### findNth\n\n```typescript\n\nfindNth\u003cT\u003e(predicate: (x: T) =\u003e boolean, nth: number): (list: T[]) =\u003e T | undefined\n```\n\nIt returns the `nth` element of `list` that satisfy the `predicate` function.\n\n```javascript\nconst predicate = x =\u003e R.type(x.foo) === 'Number'\nconst list = [{foo: 0}, {foo: 1}, {foo: 2}, {foo: 3}]\n\nconst result = R.findNth(predicate, 2)(list)\n// =\u003e {foo: 2}\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20predicate%20%3D%20x%20%3D%3E%20R.type(x.foo)%20%3D%3D%3D%20'Number'%0Aconst%20list%20%3D%20%5B%7Bfoo%3A%200%7D%2C%20%7Bfoo%3A%201%7D%2C%20%7Bfoo%3A%202%7D%2C%20%7Bfoo%3A%203%7D%5D%0A%0Aconst%20result%20%3D%20R.findNth(predicate%2C%202)(list)%0A%2F%2F%20%3D%3E%20%7Bfoo%3A%202%7D\"\u003eTry this \u003cstrong\u003eR.findNth\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nfindNth\u003cT\u003e(predicate: (x: T) =\u003e boolean, nth: number): (list: T[]) =\u003e T | undefined;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.findNth\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function findNth(predicate, nth) {\n  return list =\u003e {\n    let index = 0\n    const len = list.length\n\n    while (index \u003c len) {\n      const x = list[index]\n      if (predicate(x)) {\n\t\t\t\tif (nth === 0) return x\n\t\t\t\tnth--\n      }\n\n      index++\n    }\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { findNth } from './findNth.js'\n\nconst list = [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }]\n\ntest('happy', () =\u003e {\n  const fn = x =\u003e x.a \u003e 1\n  expect(findNth(fn,1)(list)).toEqual({ a: 3 })\n})\n\ntest('nothing is found', () =\u003e {\n\tconst fn = x =\u003e x.a \u003e 4\n\texpect(findNth(fn,1)(list)).toBeUndefined()\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#findNth)\n\n### flatMap\n\n```typescript\n\nflatMap\u003cT, U extends unknown\u003e(transformFn: (x: T extends any[] ? T[number]: never) =\u003e U): (listOfLists: T[]) =\u003e U[]\n```\n\nIt maps `fn` over `list` and then flatten the result by one-level.\n\n```javascript\nconst duplicate = n =\u003e [ n, n ]\nconst list = [ 1, 2, 3 ]\n\nconst result = R.flatMap(duplicate)(list)\n// =\u003e [ 1, 1, 2, 2, 3, 3 ]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20duplicate%20%3D%20n%20%3D%3E%20%5B%20n%2C%20n%20%5D%0Aconst%20list%20%3D%20%5B%201%2C%202%2C%203%20%5D%0A%0Aconst%20result%20%3D%20R.flatMap(duplicate)(list)%0A%2F%2F%20%3D%3E%20%5B%201%2C%201%2C%202%2C%202%2C%203%2C%203%20%5D\"\u003eTry this \u003cstrong\u003eR.flatMap\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nflatMap\u003cT, U extends unknown\u003e(transformFn: (x: T extends any[] ? T[number]: never) =\u003e U): (listOfLists: T[]) =\u003e U[];\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.flatMap\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function flatMap(fn) {\n  return list =\u003e [].concat(...list.map(fn))\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { flatMap } from './flatMap.js'\n\nconst duplicate = n =\u003e [n, n]\n\ntest('happy', () =\u003e {\n  const fn = x =\u003e [x * 2]\n  const list = [1, 2, 3]\n\n  const result = flatMap(fn)(list)\n\n  expect(result).toEqual([2, 4, 6])\n})\n\ntest('maps then flattens one level', () =\u003e {\n  expect(flatMap(duplicate)([1, 2, 3])).toEqual([1, 1, 2, 2, 3, 3])\n})\n\ntest('maps then flattens one level', () =\u003e {\n  expect(flatMap(duplicate)([1, 2, 3])).toEqual([1, 1, 2, 2, 3, 3])\n})\n\ntest('flattens only one level', () =\u003e {\n  const nest = n =\u003e [[n]]\n  expect(flatMap(nest)([1, 2, 3])).toEqual([[1], [2], [3]])\n})\n\ntest('can compose', () =\u003e {\n  function dec(x) {\n    return [x - 1]\n  }\n  function times2(x) {\n    return [x * 2]\n  }\n\n  const mdouble = flatMap(times2)\n  const mdec = flatMap(dec)\n  expect(mdec(mdouble([10, 20, 30]))).toEqual([19, 39, 59])\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { flatMap, pipe } from 'rambda'\n\ndescribe('R.flatMap', () =\u003e {\n  it('happy', () =\u003e {\n    const listOfLists: string[][] = [\n      ['f', 'bar'],\n      ['baz', 'b'],\n    ]\n    const result = pipe(\n      listOfLists,\n      x =\u003e x,\n      flatMap(x =\u003e {\n        x // $ExpectType string\n        return Number(x) + 1\n      }),\n    )\n    result // $ExpectType number[]\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#flatMap)\n\n### flatten\n\n```typescript\n\nflatten\u003cT\u003e(list: any[]): T[]\n```\n\nIt deeply flattens an array.\nYou must pass expected output type as a type argument.\n\n```javascript\nconst result = R.flatten\u003cnumber\u003e([\n  1, \n  2, \n  [3, 30, [300]], \n  [4]\n])\n// =\u003e [ 1, 2, 3, 30, 300, 4 ]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.flatten%3Cnumber%3E(%5B%0A%20%201%2C%20%0A%20%202%2C%20%0A%20%20%5B3%2C%2030%2C%20%5B300%5D%5D%2C%20%0A%20%20%5B4%5D%0A%5D)%0A%2F%2F%20%3D%3E%20%5B%201%2C%202%2C%203%2C%2030%2C%20300%2C%204%20%5D\"\u003eTry this \u003cstrong\u003eR.flatten\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nflatten\u003cT\u003e(list: any[]): T[];\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.flatten\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { isArray } from './_internals/isArray.js'\n\nexport function flatten(list, input) {\n  const willReturn = input === undefined ? [] : input\n\n  for (let i = 0; i \u003c list.length; i++) {\n    if (isArray(list[i])) {\n      flatten(list[i], willReturn)\n    } else {\n      willReturn.push(list[i])\n    }\n  }\n\n  return willReturn\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { flatten } from './flatten.js'\n\ntest('happy', () =\u003e {\n  expect(flatten([1, 2, 3, [[[[[4]]]]]])).toEqual([1, 2, 3, 4])\n\n  expect(flatten([1, [2, [[3]]], [4]])).toEqual([1, 2, 3, 4])\n\n  expect(flatten([1, [2, [[[3]]]], [4]])).toEqual([1, 2, 3, 4])\n\n  expect(flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]])).toEqual([\n    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,\n  ])\n})\n\ntest('readme example', () =\u003e {\n  const result = flatten([1, 2, [3, 30, [300]], [4]])\n  expect(result).toEqual([1, 2, 3, 30, 300, 4])\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { flatten, pipe } from 'rambda'\n\ndescribe('flatten', () =\u003e {\n  it('happy', () =\u003e {\n    const result = pipe([1, 2, [3, [4]]], flatten\u003cnumber\u003e)\n    result // $ExpectType number[]\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#flatten)\n\n### groupBy\n\nIt splits `list` according to a provided `groupFn` function and returns an object.\n\n```javascript\nconst list = [ 'a', 'b', 'aa', 'bb' ]\nconst groupFn = x =\u003e x.length\n\nconst result = R.groupBy(groupFn, list)\n// =\u003e { '1': ['a', 'b'], '2': ['aa', 'bb'] }\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%20'a'%2C%20'b'%2C%20'aa'%2C%20'bb'%20%5D%0Aconst%20groupFn%20%3D%20x%20%3D%3E%20x.length%0A%0Aconst%20result%20%3D%20R.groupBy(groupFn%2C%20list)%0A%2F%2F%20%3D%3E%20%7B%20'1'%3A%20%5B'a'%2C%20'b'%5D%2C%20'2'%3A%20%5B'aa'%2C%20'bb'%5D%20%7D\"\u003eTry this \u003cstrong\u003eR.groupBy\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#groupBy)\n\n### head\n\n```typescript\n\nhead\u003cT\u003e(listOrString: T): T extends string ? string : \n\tT extends [] ? undefined: \n\t\tT extends readonly [infer F, ...infer R] ? F : \n\t\t\tT extends readonly [infer F] ? F :\n\t\t\t\tT extends [infer F] ? F :\n\t\t\t\t\tT extends [infer F, ...infer R] ? F : \n\t\t\t\t\t\tT extends unknown[] ? T[number] : \n\t\t\t\t\t\t\tundefined\n```\n\nIt returns the first element of list or string `input`. It returns `undefined` if array has length of 0.\n\n```javascript\nconst result = [\n  R.head([1, 2, 3]),\n  R.head('foo') \n]\n// =\u003e [1, 'f']\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.head(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.head('foo')%20%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%20'f'%5D\"\u003eTry this \u003cstrong\u003eR.head\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nhead\u003cT\u003e(listOrString: T): T extends string ? string : \n\tT extends [] ? undefined: \n\t\tT extends readonly [infer F, ...infer R] ? F : \n\t\t\tT extends readonly [infer F] ? F :\n\t\t\t\tT extends [infer F] ? F :\n\t\t\t\t\tT extends [infer F, ...infer R] ? F : \n\t\t\t\t\t\tT extends unknown[] ? T[number] : \n\t\t\t\t\t\t\tundefined;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.head\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function head(listOrString) {\n  if (typeof listOrString === 'string') {\n    return listOrString[0] || ''\n  }\n\n  return listOrString[0]\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { head } from './head.js'\n\ntest('head', () =\u003e {\n  expect(head(['fi', 'fo', 'fum'])).toBe('fi')\n  expect(head([])).toBeUndefined()\n  expect(head('foo')).toBe('f')\n  expect(head('')).toBe('')\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { head, last } from 'rambda'\n\nexport const mixedList = [1, 'foo', 3, 'bar']\nexport const mixedListConst = [1, 'foo', 3, 'bar'] as const\nexport const numberList = [1, 2, 3]\nexport const numberListConst = [1, 2, 3] as const\nexport const emptyList = []\nexport const emptyString = ''\nexport const string = 'foo'\n\ndescribe('R.head', () =\u003e {\n  it('string', () =\u003e {\n    head(string) // $ExpectType string\n    last(string) // $ExpectType string\n  })\n  it('empty string', () =\u003e {\n    head(emptyString) // $ExpectType string\n    last(emptyString) // $ExpectType string\n  })\n  it('array', () =\u003e {\n    head(numberList) // $ExpectType number\n    head(numberListConst) // $ExpectType 1\n\n    last(numberList) // $ExpectType number\n    last(numberListConst) // $ExpectType 3\n  })\n  it('empty array', () =\u003e {\n    const list = [] as const\n    head(emptyList) // $ExpectType never\n    head(list) // $ExpectType undefined\n    last(emptyList) // $ExpectType never\n    last(list) // $ExpectType undefined\n  })\n\n  it('mixed', () =\u003e {\n    head(mixedList) // $ExpectType string | number\n    head(mixedListConst) // $ExpectType 1\n    last(mixedList) // $ExpectType string | number\n    last(mixedListConst) // $ExpectType \"bar\"\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#head)\n\n### includes\n\n```typescript\n\nincludes\u003cT extends string\u003e(valueToFind: T): (input: string) =\u003e boolean\n```\n\nIf `input` is string, then this method work as native `String.includes`.\n\nIf `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list.\n\n```javascript\nconst result = [\n  R.includes('oo')('foo'),\n  R.includes({a: 1})([{a: 1}])\n]\n// =\u003e [true, true ]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.includes('oo')('foo')%2C%0A%20%20R.includes(%7Ba%3A%201%7D)(%5B%7Ba%3A%201%7D%5D)%0A%5D%0A%2F%2F%20%3D%3E%20%5Btrue%2C%20true%20%5D\"\u003eTry this \u003cstrong\u003eR.includes\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nincludes\u003cT extends string\u003e(valueToFind: T): (input: string) =\u003e boolean;\nincludes\u003cT\u003e(valueToFind: T): (input: T[]) =\u003e boolean;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.includes\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { isArray } from './_internals/isArray.js'\nimport { _indexOf } from './equals.js'\n\nexport function includes(valueToFind) {\n  return iterable =\u003e {\n    if (typeof iterable === 'string') {\n      return iterable.includes(valueToFind)\n    }\n    if (!iterable) {\n      throw new TypeError(`Cannot read property \\'indexOf\\' of ${iterable}`)\n    }\n    if (!isArray(iterable)) {\n      return false\n    }\n\n    return _indexOf(valueToFind, iterable) \u003e -1\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { includes } from './includes.js'\n\ntest('with string as iterable', () =\u003e {\n  const str = 'foo bar'\n\n  expect(includes('bar')(str)).toBeTruthy()\n  expect(includes('never')(str)).toBeFalsy()\n})\n\ntest('with array as iterable', () =\u003e {\n  const arr = [1, 2, 3]\n\n  expect(includes(2)(arr)).toBeTruthy()\n  expect(includes(4)(arr)).toBeFalsy()\n})\n\ntest('with list of objects as iterable', () =\u003e {\n  const arr = [{ a: 1 }, { b: 2 }, { c: 3 }]\n\n  expect(includes({ c: 3 })(arr)).toBeTruthy()\n})\n\ntest('with NaN', () =\u003e {\n  const result = includes(Number.NaN)([Number.NaN])\n  expect(result).toBeTruthy()\n})\n\ntest('with wrong input that does not throw', () =\u003e {\n  const result = includes(1)(/foo/g)\n  expect(result).toBeFalsy()\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { includes, pipe } from 'rambda'\n\ndescribe('R.includes', () =\u003e {\n  it('happy', () =\u003e {\n    const list = [{ a: { b: '1' } }, { a: { b: '2' } }, { a: { b: '3' } }]\n    const result = pipe(list, includes({ a: { b: '1' } }))\n    result // $ExpectType boolean\n  })\n  it('with string', () =\u003e {\n    const result = pipe('foo', includes('bar'))\n    result // $ExpectType boolean\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#includes)\n\n### indexOf\n\nIt uses `R.equals` for list of objects/arrays or native `indexOf` for any other case.\n\n```javascript\nconst result = [\n  R.indexOf({a:1})([{a:1}, {a:2}]),\n  R.indexOf(2)([1, 2, 3]),\n]\n// =\u003e [0, 1]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.indexOf(%7Ba%3A1%7D)(%5B%7Ba%3A1%7D%2C%20%7Ba%3A2%7D%5D)%2C%0A%20%20R.indexOf(2)(%5B1%2C%202%2C%203%5D)%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B0%2C%201%5D\"\u003eTry this \u003cstrong\u003eR.indexOf\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#indexOf)\n\n### init\n\n```typescript\n\ninit\u003cT extends unknown[]\u003e(input: T): T extends readonly [...infer U, any] ? U : [...T]\n```\n\nIt returns all but the last element of list or string `input`.\n\n```javascript\nconst result = [\n  R.init([1, 2, 3]) , \n  R.init('foo')  // =\u003e 'fo'\n]\n// =\u003e [[1, 2], 'fo']\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.init(%5B1%2C%202%2C%203%5D)%20%2C%20%0A%20%20R.init('foo')%20%20%2F%2F%20%3D%3E%20'fo'%0A%5D%0A%2F%2F%20%3D%3E%20%5B%5B1%2C%202%5D%2C%20'fo'%5D\"\u003eTry this \u003cstrong\u003eR.init\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ninit\u003cT extends unknown[]\u003e(input: T): T extends readonly [...infer U, any] ? U : [...T];\ninit(input: string): string;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.init\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { baseSlice } from './_internals/baseSlice.js'\n\nexport function init(input) {\n  if (typeof input === 'string') {\n    return input.slice(0, -1)\n  }\n\n  return input.length ? baseSlice(input, 0, -1) : []\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { init } from './init.js'\n\ntest('with array', () =\u003e {\n  expect(init([1, 2, 3])).toEqual([1, 2])\n  expect(init([1, 2])).toEqual([1])\n  expect(init([1])).toEqual([])\n  expect(init([])).toEqual([])\n  expect(init([])).toEqual([])\n  expect(init([1])).toEqual([])\n})\n\ntest('with string', () =\u003e {\n  expect(init('foo')).toBe('fo')\n  expect(init('f')).toBe('')\n  expect(init('')).toBe('')\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { init } from 'rambda'\n\ndescribe('R.init', () =\u003e {\n  it('with string', () =\u003e {\n    const result = init('foo')\n\n    result // $ExpectType string\n  })\n  it('with list - one type', () =\u003e {\n    const result = init([1, 2, 3])\n\n    result // $ExpectType number[]\n  })\n  it('with list - mixed types', () =\u003e {\n    const result = init([1, 2, 3, 'foo', 'bar'])\n\n    result // $ExpectType (string | number)[]\n  })\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#init)\n\n### innerJoin\n\nIt returns a new list by applying a `predicate` function to all elements of `list1` and `list2` and keeping only these elements where `predicate` returns `true`.\n\n```javascript\nconst list1 = [1, 2, 3, 4, 5]\nconst list2 = [4, 5, 6]\nconst predicate = (x, y) =\u003e x \u003e= y\nconst result = R.innerJoin(predicate, list1)(list2)\n// =\u003e [4, 5]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list1%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%0Aconst%20list2%20%3D%20%5B4%2C%205%2C%206%5D%0Aconst%20predicate%20%3D%20(x%2C%20y)%20%3D%3E%20x%20%3E%3D%20y%0Aconst%20result%20%3D%20R.innerJoin(predicate%2C%20list1)(list2)%0A%2F%2F%20%3D%3E%20%5B4%2C%205%5D\"\u003eTry this \u003cstrong\u003eR.innerJoin\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#innerJoin)\n\n### interpolate\n\n```typescript\n\ninterpolate(inputWithTags: string): (templateArguments: object) =\u003e string\n```\n\nIt generates a new string from `inputWithTags` by replacing all `{{x}}` occurrences with values provided by `templateArguments`.\n\n```javascript\nconst inputWithTags = 'foo is {{bar}} even {{a}} more'\nconst templateArguments = {\"bar\":\"BAR\", a: 1}\n\nconst result = R.interpolate(inputWithTags, templateArguments)\nconst expected = 'foo is BAR even 1 more'\n// =\u003e `result` is equal to `expected`\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20inputWithTags%20%3D%20'foo%20is%20%7B%7Bbar%7D%7D%20even%20%7B%7Ba%7D%7D%20more'%0Aconst%20templateArguments%20%3D%20%7B%22bar%22%3A%22BAR%22%2C%20a%3A%201%7D%0A%0Aconst%20result%20%3D%20R.interpolate(inputWithTags%2C%20templateArguments)%0Aconst%20expected%20%3D%20'foo%20is%20BAR%20even%201%20more'%0A%2F%2F%20%3D%3E%20%60result%60%20is%20equal%20to%20%60expected%60\"\u003eTry this \u003cstrong\u003eR.interpolate\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\ninterpolate(inputWithTags: string): (templateArguments: object) =\u003e string;\n\n// API_MARKER_END\n// ============================================\n\nexport as namespace R\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.interpolate\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nconst getOccurrences = input =\u003e input.match(/{{\\s*.+?\\s*}}/g)\nconst getOccurrenceProp = occurrence =\u003e occurrence.replace(/{{\\s*|\\s*}}/g, '')\n\nconst replace = ({ inputHolder, prop, replacer }) =\u003e {\n  const regexBase = `{{${prop}}}`\n  const regex = new RegExp(regexBase, 'g')\n  return inputHolder.replace(regex, replacer)\n}\n\nexport function interpolate(input) {\n  return templateInput =\u003e {\n    const occurrences = getOccurrences(input)\n    if (occurrences === null) {\n      return input\n    }\n    let inputHolder = input\n\n    for (const occurrence of occurrences) {\n      const prop = getOccurrenceProp(occurrence)\n      inputHolder = replace({\n        inputHolder,\n        prop,\n        replacer: templateInput[prop],\n      })\n    }\n\n    return inputHolder\n  }\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { interpolate } from './interpolate.js'\nimport { pipe } from './pipe.js'\n\ntest('happy', () =\u003e {\n  const result = pipe(\n\t\t{ name: 'John', age: 30 },\n\t\tinterpolate('My name is {{name}} and I am {{age}} years old')\n\t)\n\texpect(result).toBe('My name is John and I am 30 years old')\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { interpolate } from 'rambda'\n\nconst templateInput = 'foo {{x}} baz'\nconst templateArguments = { x: 'led zeppelin' }\n\nit('R.interpolate', () =\u003e {\n\tconst result = interpolate(templateInput)(templateArguments)\n\n\tresult // $ExpectType string\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#interpolate)\n\n### intersection\n\nIt loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.\n\n\u003e :boom: There is slight difference between Rambda and Ramda implementation. Ramda.intersection(['a', 'b', 'c'], ['c', 'b']) result is \"[ 'c', 'b' ]\", but Rambda result is \"[ 'b', 'c' ]\".\n\n```javascript\nconst listA = [ { id : 1 }, { id : 2 }, { id : 3 }, { id : 4 } ]\nconst listB = [ { id : 3 }, { id : 4 }, { id : 5 }, { id : 6 } ]\n\nconst result = R.intersection(listA)(listB)\n// =\u003e [{ id : 3 }, { id : 4 }]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20listA%20%3D%20%5B%20%7B%20id%20%3A%201%20%7D%2C%20%7B%20id%20%3A%202%20%7D%2C%20%7B%20id%20%3A%203%20%7D%2C%20%7B%20id%20%3A%204%20%7D%20%5D%0Aconst%20listB%20%3D%20%5B%20%7B%20id%20%3A%203%20%7D%2C%20%7B%20id%20%3A%204%20%7D%2C%20%7B%20id%20%3A%205%20%7D%2C%20%7B%20id%20%3A%206%20%7D%20%5D%0A%0Aconst%20result%20%3D%20R.intersection(listA)(listB)%0A%2F%2F%20%3D%3E%20%5B%7B%20id%20%3A%203%20%7D%2C%20%7B%20id%20%3A%204%20%7D%5D\"\u003eTry this \u003cstrong\u003eR.intersection\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#intersection)\n\n### intersperse\n\nIt adds a `separator` between members of `list`.\n\n```javascript\nconst list = [ 0, 1, 2, 3 ]\nconst separator = 10\nconst result = R.intersperse(separator)(list)\n// =\u003e [0, 10, 1, 10, 2, 10, 3]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B%200%2C%201%2C%202%2C%203%20%5D%0Aconst%20separator%20%3D%2010%0Aconst%20result%20%3D%20R.intersperse(separator)(list)%0A%2F%2F%20%3D%3E%20%5B0%2C%2010%2C%201%2C%2010%2C%202%2C%2010%2C%203%5D\"\u003eTry this \u003cstrong\u003eR.intersperse\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#intersperse)\n\n### join\n\n```typescript\n\njoin\u003cT\u003e(glue: string): (list: T[]) =\u003e string\n```\n\nIt returns a string of all `list` instances joined with a `glue`.\n\n```javascript\nR.join('-', [1, 2, 3])  // =\u003e '1-2-3'\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20R.join('-'%2C%20%5B1%2C%202%2C%203%5D)%20%20%2F%2F%20%3D%3E%20'1-2-3'\"\u003eTry this \u003cstrong\u003eR.join\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\njoin\u003cT\u003e(glue: string): (list: T[]) =\u003e string;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.join\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function join(glue) {\n  return list =\u003e list.join(glue)\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { join, pipe } from 'rambda'\n\nit('R.join', () =\u003e {\n  const result = pipe([1, 2, 3], join('|'))\n  result // $ExpectType string\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#join)\n\n### last\n\n```typescript\n\nlast\u003cT\u003e(listOrString: T): T extends string ? string : \n  T extends [] ? undefined : \n    T extends readonly [...infer R, infer L] ? L : \n      T extends readonly [infer L] ? L :\n        T extends [infer L] ? L :\n          T extends [...infer R, infer L] ? L : \n            T extends unknown[] ? T[number] : \n              undefined\n```\n\nIt returns the last element of `input`, as the `input` can be either a string or an array. It returns `undefined` if array has length of 0.\n\n```javascript\nconst result = [\n  R.last([1, 2, 3]),\n  R.last('foo'),\n]\n// =\u003e [3, 'o']\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.last(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.last('foo')%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B3%2C%20'o'%5D\"\u003eTry this \u003cstrong\u003eR.last\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nlast\u003cT\u003e(listOrString: T): T extends string ? string : \n  T extends [] ? undefined : \n    T extends readonly [...infer R, infer L] ? L : \n      T extends readonly [infer L] ? L :\n        T extends [infer L] ? L :\n          T extends [...infer R, infer L] ? L : \n            T extends unknown[] ? T[number] : \n              undefined;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.last\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function last(listOrString) {\n  if (typeof listOrString === 'string') {\n    return listOrString[listOrString.length - 1] || ''\n  }\n\n  return listOrString[listOrString.length - 1]\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { last } from './last.js'\n\ntest('with list', () =\u003e {\n  expect(last([1, 2, 3])).toBe(3)\n  expect(last([])).toBeUndefined()\n})\n\ntest('with string', () =\u003e {\n  expect(last('abc')).toBe('c')\n  expect(last('')).toBe('')\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#last)\n\n### lastIndexOf\n\n```typescript\n\nlastIndexOf\u003cT\u003e(target: T): (list: T[]) =\u003e number\n```\n\nIt returns the last index of `target` in `list` array.\n\n`R.equals` is used to determine equality between `target` and members of `list`.\n\nIf there is no such index, then `-1` is returned.\n\n```javascript\nconst list = [1, 2, 3, 1, 2, 3]\nconst result = [\n  R.lastIndexOf(2)(list),\n  R.lastIndexOf(4)(list),\n]\n// =\u003e [4, -1]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20list%20%3D%20%5B1%2C%202%2C%203%2C%201%2C%202%2C%203%5D%0Aconst%20result%20%3D%20%5B%0A%20%20R.lastIndexOf(2)(list)%2C%0A%20%20R.lastIndexOf(4)(list)%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B4%2C%20-1%5D\"\u003eTry this \u003cstrong\u003eR.lastIndexOf\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nlastIndexOf\u003cT\u003e(target: T): (list: T[]) =\u003e number;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.lastIndexOf\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nimport { _lastIndexOf } from './equals.js'\n\nexport function lastIndexOf(valueToFind) {\n  return list =\u003e _lastIndexOf(valueToFind, list)\n}\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTests\u003c/strong\u003e\u003c/summary\u003e\n\n```javascript\nimport { lastIndexOf } from './lastIndexOf.js'\n\ntest('with NaN', () =\u003e {\n  expect(lastIndexOf(Number.NaN)([Number.NaN])).toBe(0)\n})\n\ntest('will throw with bad input', () =\u003e {\n  expect(() =\u003e indexOf([])(true)).toThrowError('indexOf is not defined')\n})\n\ntest('without list of objects - no R.equals', () =\u003e {\n  expect(lastIndexOf(3)([1, 2, 3, 4])).toBe(2)\n  expect(lastIndexOf(10)([1, 2, 3, 4])).toBe(-1)\n})\n\ntest('list of objects uses R.equals', () =\u003e {\n  const listOfObjects = [{ a: 1 }, { b: 2 }, { c: 3 }]\n  expect(lastIndexOf({ c: 4 })(listOfObjects)).toBe(-1)\n  expect(lastIndexOf({ c: 3 })(listOfObjects)).toBe(2)\n})\n\ntest('list of arrays uses R.equals', () =\u003e {\n  const listOfLists = [[1], [2, 3], [2, 3, 4], [2, 3], [1], []]\n  expect(lastIndexOf([])(listOfLists)).toBe(5)\n  expect(lastIndexOf([1])(listOfLists)).toBe(4)\n  expect(lastIndexOf([2, 3, 4])(listOfLists)).toBe(2)\n  expect(lastIndexOf([2, 3, 5])(listOfLists)).toBe(-1)\n})\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e test\u003c/summary\u003e\n\n```typescript\nimport { lastIndexOf, pipe } from 'rambda'\n\ndescribe('R.lastIndexOf', () =\u003e {\n  const result = pipe([{ a: 1 }, { a: 2 }, { a: 3 }], lastIndexOf({ a: 2 }))\n  result // $ExpectType number\n})\n```\n\n\u003c/details\u003e\n\n[![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#lastIndexOf)\n\n### map\n\n```typescript\n\nmap\u003cT extends IterableContainer, U\u003e(\n  fn: (value: T[number], index: number) =\u003e U,\n): (data: T) =\u003e Mapped\u003cT, U\u003e\n```\n\nIt returns the result of looping through `iterable` with `fn`.\n\nIt works with both array and object.\n\n```javascript\nconst fn = x =\u003e x * 2\n\nconst iterable = [1, 2]\nconst obj = {a: 1, b: 2}\n\nconst result = R.map(fn)(iterable),\n// =\u003e [2, 4]\n```\n\n\u003ca title=\"redirect to Rambda Repl site\" href=\"https://rambda.now.sh?const%20fn%20%3D%20x%20%3D%3E%20x%20*%202%0A%0Aconst%20iterable%20%3D%20%5B1%2C%202%5D%0Aconst%20obj%20%3D%20%7Ba%3A%201%2C%20b%3A%202%7D%0A%0Aconst%20result%20%3D%20R.map(fn)(iterable)%2C%0A%2F%2F%20%3D%3E%20%5B2%2C%204%5D\"\u003eTry this \u003cstrong\u003eR.map\u003c/strong\u003e example in Rambda REPL\u003c/a\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003eAll TypeScript definitions\u003c/summary\u003e\n\n```typescript\nmap\u003cT extends IterableContainer, U\u003e(\n  fn: (value: T[number], index: number) =\u003e U,\n): (data: T) =\u003e Mapped\u003cT, U\u003e;\nmap\u003cT extends IterableContainer, U\u003e(\n  fn: (value: T[number]) =\u003e U,\n): (data: T) =\u003e Mapped\u003cT, U\u003e;\nmap\u003cT extends IterableContainer, U\u003e(\n  fn: (value: T[number], index: number) =\u003e U,\n\tdata: T\n) : Mapped\u003cT, U\u003e;\nmap\u003cT extends IterableContainer, U\u003e(\n  fn: (value: T[number]) =\u003e U,\n\tdata: T\n) : Mapped\u003cT, U\u003e;\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003cstrong\u003eR.map\u003c/strong\u003e source\u003c/summary\u003e\n\n```javascript\nexport function map(fn) {\n  return list =\u003e {\n    let index = 0\n    const willReturn = Array(list.length)\n    while (index \u003c list.length) {\n      willReturn[","project_url":"https://awesome.ecosyste.ms/api/v1/projects/selfrefactor.github.io%2Frambda%2F","html_url":"https://awesome.ecosyste.ms/projects/selfrefactor.github.io%2Frambda%2F","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/selfrefactor.github.io%2Frambda%2F/lists"}