{"id":17382218,"url":"https://github.com/brainrake/fuc","last_synced_at":"2025-07-25T17:15:11.603Z","repository":{"id":34768559,"uuid":"38750641","full_name":"brainrake/fuc","owner":"brainrake","description":"Functional Utilities for Coffeescript and Javascript","archived":false,"fork":false,"pushed_at":"2015-08-21T17:07:28.000Z","size":136,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-12T11:53:28.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brainrake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-08T11:44:23.000Z","updated_at":"2015-07-27T06:52:09.000Z","dependencies_parsed_at":"2022-08-31T02:51:08.690Z","dependency_job_id":null,"html_url":"https://github.com/brainrake/fuc","commit_stats":null,"previous_names":["brainrape/fuc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brainrake/fuc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Ffuc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Ffuc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Ffuc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Ffuc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainrake","download_url":"https://codeload.github.com/brainrake/fuc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Ffuc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267038377,"owners_count":24025612,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-16T07:35:51.667Z","updated_at":"2025-07-25T17:15:11.542Z","avatar_url":"https://github.com/brainrake.png","language":"CoffeeScript","readme":"Functional Utilities for Coffeescript and Javascript\n----------------------------------------------------\n\n`Underscore`/`lodash` too much but never enough?\n\nSo you have `async` for breaking all your `Promise`s?\n\nFuc it all!\n\n```bash\n\u003e npm install fuc\n```\n\n```coffeescript\nrequire('fuc')._it_all()           # fuc the global namespace, fuc prototypes\n\n1 + __ 2                           # logs 2, returns 3\n\nunite {a: 1}, {b: 2}               # =\u003e {a: 1, b: 2}\n\ndo thus {a: 1}, -\u003e this.a + 1      # =\u003e 2\n\n[1, 2, 4]._fap (it) -\u003e\n  if it%2 then null else it-2      # =\u003e [0, 2]\n```\n\nAlso, fuc the browser (TODO)\n\n```bash\n\u003e bower install fuc\n```\n\n```html\n\u003cscript src='bower_components/fuc/fuc.min.js'\u003e\u003c/script\u003e\n\u003cscript\u003eFuc._it_all()\u003c/script\u003e\n```\n\nIf you think that looks dangerous, you can fuc less but stay safe:\n\n```coffeescript\n{__, fap, thus, unite} = require 'fuc'\n```\n\nSrsly? Why?\n-----------\n\nYes. `lodash` is nice, but functions aren't curried, and some are sorely missing (like `flip`).\n\nSo, here's a bundle of functions, in all its 22-line glory, that most of the time obviates the need to include helper libraries, for me at least.\n\nI'll add some `async` helpers as well, I `promise`!\n\n\nDocumentation\n-------------\n\nUse [the source](fuc.coffee)!\n\nAlso see some [examples](test.coffee).\n\n\n```coffeescript\ncurry : (Function) -\u003e Function\nfunction._curry :()-\u003e Function\n# takes a function with two or more arguments, returns a function that can\n# be called either with two or more arguments (same as the original),\n# or with one argument, in which case it returns a function that awaits\n# the second argument and possibly more - ultimate flexibility\n\nisO : (value) -\u003e Boolean\nvalue._isO :()-\u003e Boolean\n# returns true if value is not a primitive\n\npp : (value) -\u003e String\nvalue._pp :()-\u003e String\n# toString primitives; JSON.stringify and indent objects\n\n__ : (arg [, args...]) -\u003e arg\narg.__ :   ([args...]) -\u003e arg\n# console.log all arguments, return the first one; uses pp\n\n___ : (prefix, arg [, args...]) -\u003e arg\narg.___ :  (prefix [, args...]) -\u003e arg\n# console.log prefix and all args, return first arg (after prefix); uses pp\n\nflip : (Function(a, b [, c...])) -\u003e Function(b, a [, c...])\nfunction(a, b [, c...])._flip :()-\u003e Function(b, a [, c...])\n# takes a function with two or more arguments, returns it with the first two\n# arguments flipped, and curried\n\nflap : (arg, Function [, args...]) -\u003e result\nobj._flap : (Function [, args...]) -\u003e result\n# applies the function to the argument(s); `flip apply`\n\ndnib : (this_object, Function) -\u003e Function\nthis_object._dnib : (Function) -\u003e Function\n# bind the `this` object in the function body; flipped `Function.bind`\n\nunite : (Object1, Object2 [, Objects...]) -\u003e Object\nobject1._unite : (Object2 [, Objects...]) -\u003e Object\n# create a new object with properties merged from all the arguments\n\nmaf : (Function, Array) -\u003e Array\narray._maf : (Function) -\u003e Array\n# map, then filter out undefineds and nulls (but not `false`s, `0`s or ''s)\n\nzop : (Array) -\u003e Object\narray._zop :()-\u003e Object\n# create an object from a list of pairs of [key, value]\n```\n\nAll functions with two or more arguments can be used in a curried fashion: If you call them with only one argument, they will return a function awaiting the other argument (and any optional arguments).\n\nPrototypes of built-in objects like `Object` and `Array` are only extended if you call `Fuc._it_all()`, and the new methods always start with an underscore to avoid name clashes.\n\n\nMotivating Examples\n-------------------\n\n### `__`\n\nI'm not saying we're stuck with `console.log` debugging in javascript. But it's the easiest, and yields the most results for the effort.\nInspecting runtime values is much more important than in static languages: where proper languages throw errors, Javascript does something stupid and moves on like nothing happened. So you need to trace expressions' values to see what's going on. You could do that by setting breakpoints and watches, but that stops program execution and you need to muck about in Developer Tools. It's not so straightforward in `node.js`.\n\nLogging could be more convenient though. When you want to log a subexpression, you have to copy it, since console.log doesn't return anything. Also, it's kind of boring to type it all the time. Well, that's fixed now, just insert `__` wherever, and add parens as needed.\n\n```coffeescript\n     Array(16).join(__ 'here'-1) + 'Fapman'     # logs 'NaN'\n```\n\nTo log extra information, use `___`\n\n```coffeescript\n     fs.readFile (___ 'reading') 'file.txt'     # logs 'reading file.txt'\n```\n\nI used to include the definition for `__` at the top of every single Coffeescript/Javascript source file I wrote, plus usually a few of the other functions here. Now I don't have to.\n\n### `unite`\n\nLodash and jQuery have `extend`. It's why I include lodash most of the time (along with zipObject). But it mutates the argument. Bleah.\n\n### `flap`\n\nSo you want to write the argument first, and then the function you to call with it. Coffeescript has `do` which calls the function immediately after it, and passes the arguments with the same name as the function arguments.\n\nSometimes you need more though.\n\n### `fap`\n\nFilter map. or `f(x) for x in arr when f(x) not in [null, undefined]`.\n\n\nLicense\n-------\n\nThis is free and unencumbered software released into the public domain.\n\nAnyone is free to copy, modify, publish, use, compile, sell, or\ndistribute this software, for any purpose, commercial or non-commercial.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainrake%2Ffuc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainrake%2Ffuc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainrake%2Ffuc/lists"}