{"id":17920598,"url":"https://github.com/nem035/js-functional-kitchen","last_synced_at":"2025-07-26T12:41:26.787Z","repository":{"id":92965974,"uuid":"78922956","full_name":"nem035/js-functional-kitchen","owner":"nem035","description":"Mini functional recipes in JavaScript.","archived":false,"fork":false,"pushed_at":"2017-01-16T06:30:18.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T22:12:49.985Z","etag":null,"topics":["functional-programming","javascript"],"latest_commit_sha":null,"homepage":null,"language":null,"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/nem035.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-14T07:04:00.000Z","updated_at":"2018-12-28T03:58:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"baa7d4ac-fcf3-4004-bd0c-d5ad391f9668","html_url":"https://github.com/nem035/js-functional-kitchen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fjs-functional-kitchen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fjs-functional-kitchen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fjs-functional-kitchen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem035%2Fjs-functional-kitchen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nem035","download_url":"https://codeload.github.com/nem035/js-functional-kitchen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246966146,"owners_count":20862004,"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":["functional-programming","javascript"],"created_at":"2024-10-28T20:26:17.049Z","updated_at":"2025-04-03T08:32:36.601Z","avatar_url":"https://github.com/nem035.png","language":null,"readme":"# JSFunctionalKitchen\n\nMini functional recipes in JavaScript.\n\n## Methods\n\n### `callFirst` and `callLast`\n\n```js\nconst callFirst = (fn, ...leftArgs) =\u003e (...rest) =\u003e fn(...leftArgs, ...rest);\nconst callLast = (fn, ...rightArgs) =\u003e (...rest) =\u003e fn(...rest, ...rightArgs);\n\nconst debugLogger = callFirst(console.log, 'DEBUG: ');\ndebugLogger('a', 'b') // 'DEBUG: a b'\n\nconst secondTimer = callLast(setTimeout, 1000);\nsecondTimer(() =\u003e {\n  console.log('1 second!');\n});\n```\n\n### `unary`\n\n```js\nconst unary = (fn) =\u003e fn.length === 1 ? fn : (firstArg) =\u003e fn(firstArg);\n\n['1', '2', '3'].map(unary(parseInt)) // [1, 2, 3]\n```\n\n### `tap`\n\n```js\nconst tap = (value) =\u003e (fn) =\u003e\n  (typeof(fn) === 'function' \u0026\u0026 fn(value), value)\n\nconst tap5 = tap(5);\n\ntap5(console.log); // returns and logs 5\n```\n\n### `maybe`\n\n```js\nconst maybe = (fn) =\u003e (...args) =\u003e {\n  if (args.length === 0) return;\n  for (const arg of args) {\n    if (arg === null || arg === undefined) return;\n  }\n  return fn(...args);\n};\n\nmaybe(sum)(1, 2, 3)    // 6\nmaybe(sum)(1, null, 3) // undefined\n```\n\n### `once`\n\n```js\nconst once = (fn) =\u003e (...args) =\u003e {\n  let done = false;\n  return done\n    ? void 0\n    : (done = true, fn(..args));\n}\n\nconst authenticate = once(login);\nauthenticate('admin', '123').then(console.log);\nauthenticate('admin', '123').then(console.log); // Error: undefined is not a function\n```\n\n### `firstAndRest`\n\n```js\nconst firstAndRest = (first, ...rest) =\u003e [first, rest];\n\nconst logMessage = ['DEBUG:', '1', '2', '3'];\nconst [prefix] = firstAndRest(...logMessage); // 'DEBUG:'\n```\n\n### `restAndLast`\n\n```js\nconst restAndLast = (...args) =\u003e {\n  if (args.length \u003c 1) return void 0;\n  const last = args[args.length - 1];\n  const rest = args.slice(0, args.length - 1);\n  return [rest, last];\n}\n\nconst cString = ['n', 'e', 'm', 'a', 'n', 'j', 'a', '\\0'];\nconst [letters] = restAndLast(...cString); // ['n', 'e', 'm', 'a', 'n', 'j', 'a']\n```\n\n### `takeFirst` and `takeLast`\n\n```js\nconst takeFirst = (amt) =\u003e (list) =\u003e list.slice(0, amt);\nconst takeLast = (amt) =\u003e (list) =\u003e list.slice(-amt);\n\ntakeFirst(3)([1, 2, 3, 4, 5]) // [1, 2, 3]\ntakeLast(3)([1, 2, 3, 4, 5]) // [3, 4, 5]\n```\n\n### `mapWith`\n\n```js\nconst mapWith = (fn) =\u003e (list) =\u003e list.map(fn);\nconst squaresOf = mapWith((x) =\u003e x ** 2);\nsquaresOf([1,2,3,4,5]) // [1, 4, 9, 16, 25]\n```\n\n### `flip`\n\n```js\nconst flip = (fn) =\u003e (a, b) =\u003e fn(b, a);\n\nconst callAfter = flip(setTimeout);\ncallAfter(1000, () =\u003e {\n  console.log('1 second!');\n});\n```\n\n### `flipAndCurry`\n\n```js\nconst flipAndCurry = (fn) =\u003e (a) =\u003e (b) =\u003e fn(b, a);\n\nconst callAfterSecond = flipAndCurry(setTimeout)(1000);\ncallAfterSecond(() =\u003e {\n  console.log('1 second!');\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnem035%2Fjs-functional-kitchen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnem035%2Fjs-functional-kitchen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnem035%2Fjs-functional-kitchen/lists"}