{"id":16302631,"url":"https://github.com/timonson/bashfunc","last_synced_at":"2025-07-04T12:06:39.031Z","repository":{"id":115673922,"uuid":"209675989","full_name":"timonson/bashFunc","owner":"timonson","description":"A small Bash library for functional programming - map, filter, reduce and more","archived":false,"fork":false,"pushed_at":"2019-11-06T14:02:10.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T15:22:23.179Z","etag":null,"topics":["bash","fp","functional","functional-programming","map","reduce","shell"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/timonson.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":"2019-09-20T01:04:48.000Z","updated_at":"2024-12-10T00:35:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"238214eb-b204-4567-a801-5e8b7b08a98f","html_url":"https://github.com/timonson/bashFunc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/timonson/bashFunc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timonson%2FbashFunc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timonson%2FbashFunc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timonson%2FbashFunc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timonson%2FbashFunc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timonson","download_url":"https://codeload.github.com/timonson/bashFunc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timonson%2FbashFunc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262240063,"owners_count":23280446,"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":["bash","fp","functional","functional-programming","map","reduce","shell"],"created_at":"2024-10-10T20:58:29.427Z","updated_at":"2025-06-27T10:35:05.972Z","avatar_url":"https://github.com/timonson.png","language":"Shell","readme":"# bashFunc\n\nA small Bash library for functional programming. Right now it contains **map**,\n**filter**, **reduce**, **forEach**, **some** and **split**.\n\n## API\n\n#### Callback\n\nThe callback is always the first argument and you can either use normal\nfunctions or a string with the function body inside of `()` as first argument.  \nThese two code blocks are equal:\n\n```bash\nreduce '( echo $(( $1 + $2 )) )' 0 1 2 3 4 5\n# 15\n```\n\n```bash\nadd() { echo $(($1 + $2)); }\nreduce add 0 1 2 3 4 5\n# 15\n```\n\n#### Arguments\n\nAs data input you can either use _positional arguments_ **or** the function\nreads lines from the standard input - like the native `mapfile` command does -\nand takes those as arguments. The following example demostrates the two\nalternatives:\n\n```bash\nmap '( echo $(( $1 + 10 )) )' 1 2 3 4 5\nmap '( echo $(( $1 + 10 )) )' \u003c \u003c(printf \"%s\\n\" 1 2 3 4 5)\n# 11\n# 12\n# 13\n# 14\n# 15\n```\n\n#### Compatibility\n\nYou can of course _chain_ different commands together:\n\n```bash\nreduce '( echo $(( $1 + $2 )) )' \u003c \u003c(filter '( (( $1 % 2 )) )' \u003c \u003c(map '( echo $(( $1 + 10 )) )' 1 2 3 4 5))\n# 39\n```\n\n## Examples\n\n#### Map\n\n```bash\nmap '( echo $(( $1 + 10 )) )' \u003c \u003c(printf \"%s\\n\" 1 2 3 4 5)\n# 11\n# 12\n# 13\n# 14\n# 15\n```\n\n#### Filter\n\n```bash\nfilter '( (( $1 % 2 )) )' \u003c \u003c(printf \"%s\\n\" 1 2 3 4 5)\n# 1\n# 3\n# 5\n```\n\n#### Reduce\n\nThe second argument, in this case the `10`, is the starting value of the\n_accumulator_.\n\n```bash\nreduce '( echo $(( $1 + $2 )) )' 10 \u003c \u003c(printf \"%s\\n\" 1 2 3 4 5)\n# 25\n```\n\n#### ForEach\n\n```bash\nforEach '( notify-send $1 )' \u003c \u003c(printf \"%s\\n\" 1 2 3 4 5)\n```\n\n#### Some\n\nThe `some` function tests whether at least one element passes the test\nimplemented by the provided function.\n\n```bash\nsome '((( $1 % 2 )))' \u003c \u003c(printf \"%s\\n\" 1 2 3 4 5)\n# echo $?\n# 0\n```\n\n#### Split\n\nThe API for this function is quite different. The first argument is a _string_\nand the second argument takes a _seperator_.\n\n```bash\nsplit 'Hello,World,Good,Evening' ','\n# Hello\n# World\n# Good\n# Evening\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimonson%2Fbashfunc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimonson%2Fbashfunc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimonson%2Fbashfunc/lists"}