{"id":16213890,"url":"https://github.com/menacingmecha/gd3_fp","last_synced_at":"2025-03-19T09:31:06.767Z","repository":{"id":134800044,"uuid":"493876685","full_name":"MenacingMecha/gd3_fp","owner":"MenacingMecha","description":"Minimal, single-file functional programming module for Godot Engine 3.x","archived":false,"fork":false,"pushed_at":"2022-05-31T17:00:24.000Z","size":6,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-28T17:46:57.607Z","etag":null,"topics":["functional-programming","gdscript","godot","godot-engine"],"latest_commit_sha":null,"homepage":"","language":"GDScript","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/MenacingMecha.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":"2022-05-19T01:14:37.000Z","updated_at":"2023-08-08T11:12:16.000Z","dependencies_parsed_at":"2023-05-16T04:30:52.195Z","dependency_job_id":null,"html_url":"https://github.com/MenacingMecha/gd3_fp","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/MenacingMecha%2Fgd3_fp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenacingMecha%2Fgd3_fp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenacingMecha%2Fgd3_fp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MenacingMecha%2Fgd3_fp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MenacingMecha","download_url":"https://codeload.github.com/MenacingMecha/gd3_fp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243982141,"owners_count":20378605,"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","gdscript","godot","godot-engine"],"created_at":"2024-10-10T11:08:58.074Z","updated_at":"2025-03-19T09:31:06.755Z","avatar_url":"https://github.com/MenacingMecha.png","language":"GDScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gd3_fp\nMinimal, single-file functional programming module for Godot Engine 3.0\n\nAdapted from: https://georgemarques.com.br/functional-gdscript.pdf\n\n## Usage\nPreload the script to access the static functions\n\n```gdscript\nconst FP := preload(\"res://fp.gd\")\n```\n\n## Map\n```gdscript\nstatic func map(input: Array, function: FuncRef) -\u003e Array:\n```\nCalls `function` on each element of `input`, returning the transformed outputs from `function`.\n\n`function` is required to have a non-void output.\n\n### Example\n\n```gdscript\nstatic func add_one(num: int) -\u003e int:\n\treturn num + 1\n\nvar input := [1, 2, 3]\nvar output := FP.map(input, funcref(self, \"add_one\"))  # [2, 3, 4]\n```\n\n## Filter\n```gdscript\nstatic func filter(input: Array, function: FuncRef) -\u003e Array:\n```\n\nCalls `function` on each element of `input`, returning all the elements which returned `true`.\n\n`function` should return a `bool`, but this is not required.\n\n### Example\n```gdscript\nstatic func is_even(num: int) -\u003e bool:\n\treturn num % 2 == 0\n\nvar input := [1, 2, 3, 4]\nvar output := FP.filter(input, funcref(self, \"is_even\"))  # [2, 4]\n```\n\n## Reduce\n```gdscript\nstatic func reduce(input: Array, function: FuncRef, base = null):\n```\n\nReturns a single output value by calling `function` on each element of the array along with the accumalated result of each iteration.\n\n`function` should take in two inputs.\n\n`base` can optionally be used to define a starting value.\n\n### Example\n```gdscript\nstatic func sum(a: int, b: int) -\u003e int:\n\treturn a + b\n\nvar input := [1, 2, 3]\nvar output := FP.reduce(input, funcref(self, \"sum\"))  # 6\n```\n\n## Pipe\n```gdscript\nstatic func pipe(input: Array, pipe_pairs: Array):\n```\n\nTransforms `input` in order through each `Funcref` pair in `pipe_pairs`.\n\n`pipe_pairs` is expected to be an array of arrays, with a higher-order function `Funcref` followed by an appropriate transformative function `Funcref`.\n\n### Example\n```gdscript\nvar input := [1, 2, 3, 4]\nvar output = FP.pipe(\n\tinput,\n\t[\n\t\t[funcref(FP, \"filter\"), funcref(self, \"is_even\")],\n\t\t[funcref(FP, \"map\"), funcref(self, \"add_one\")],\n\t\t[funcref(FP, \"reduce\"), funcref(self, \"sum\")]\n\t]\n)  # 8\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenacingmecha%2Fgd3_fp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmenacingmecha%2Fgd3_fp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenacingmecha%2Fgd3_fp/lists"}