{"id":20136125,"url":"https://github.com/zkfmapf123/functional_programming","last_synced_at":"2025-03-02T22:42:15.818Z","repository":{"id":115887976,"uuid":"520940052","full_name":"zkfmapf123/functional_programming","owner":"zkfmapf123","description":"함수형 프로그래밍 ","archived":false,"fork":false,"pushed_at":"2022-09-20T15:03:21.000Z","size":103,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T09:38:40.971Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/zkfmapf123.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-03T15:41:48.000Z","updated_at":"2022-08-03T17:07:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b253108-b08d-41f2-a491-94d886e0e383","html_url":"https://github.com/zkfmapf123/functional_programming","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/zkfmapf123%2Ffunctional_programming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Ffunctional_programming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Ffunctional_programming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkfmapf123%2Ffunctional_programming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zkfmapf123","download_url":"https://codeload.github.com/zkfmapf123/functional_programming/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241582521,"owners_count":19985846,"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":[],"created_at":"2024-11-13T21:17:48.689Z","updated_at":"2025-03-02T22:42:15.811Z","avatar_url":"https://github.com/zkfmapf123.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Functional Programming\n\n### Desc\n\n- 프로그램을 작은 순수함수로 만들고 -\u003e 합성\n- 공통의 가능성을 추출하고 -\u003e 합성을 통해 재사용 가능한 일반적 구성요소를 만든다\n\n### Why FP?\n\n- 명령형 코드는 -\u003e 부수효과가 얽히고 장황해진다 -\u003e 원래의 의도와는 다르게 동작한다 (부수효과)\n  - Side Effect\n  - 결과를 예측하기 어려움\n- 함수형 코드는 -\u003e 부수효과를 최소화 한다\n  - 순서나 실행횟수와 상관없이 -\u003e 항상 결과가 예측가능하다\n\n### Example\n\n```typescript\n// 명령형 코드\n\nfor (let i = 0; i \u003c 100; i++) {\n  console.log(i)\n}\n```\n\n```typescript\n// 함수형 코드\n\nfunction loop(fn, acc, list) {\n  if (list.length === 0) return acc\n\n  const [head, ...tail] = list\n  return fn, fn(acc, head), tail\n}\n\nconst range = (start, end) =\u003e\n  Array.from({length: end - start + 1}, (_, index) =\u003e index + start)\nconst plus = (a, b) =\u003e a + b\n\nconsole.log(loop(plus, 0, range(1, 100)))\n```\n\n### Options vs Try\n\n- Option\n\n```\n  에러난 사실만을 기록할 때\n```\n\n- Try\n\n```\n  에러난 이유를 가지고 오고싶을 때\n```\n\n### 명령형 vs 선언형\n\n```ts\n-- use Func 선언형\nexport const KeepSuccess =\n  \u003cE, R\u003e(tas: Array\u003cTry\u003cE, R\u003e\u003e): Array\u003cR\u003e =\u003e {\n    const ret = tas.flatMap((ta) =\u003e {\n      if (isSuccess(ta)) return [ta.result];\n      else return [];\n    })\n    return ret;\n  }\n\n-- use For (명령형)\nexport const KeepSuccessWithFor = \u003cE, R\u003e(tas: Array\u003cTry\u003cE, R\u003e\u003e): Array\u003cR\u003e =\u003e {\n  const ret: Array\u003cR\u003e = [];\n  for (const ta of tas) {\n    if (isSuccess(ta)) {\n      ret.push(ta.result);\n    }\n  }\n  return ret;\n}\n\n// 함수형 프로그래밍에서는 선언형 프로그래밍을 지향한다.\n// 명령형 코드가 나쁘다는 건 아니다.\n// 선언적인 방식의 코드는 부수효과를 파악하고 격리한다는 점에서 선언적이 형태로 사용한다면 -\u003e 사이드 이펙트를 피할 수 있다.\n```\n\n### use fp-ts (with await-to-js)\n\n- \u003ca href=\"https://gcanti.github.io/fp-ts/\"\u003efp-ts documents\u003c/a\u003e\n- https://www.npmjs.com/package/fp-ts\n- https://www.npmjs.com/package/await-to-js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkfmapf123%2Ffunctional_programming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzkfmapf123%2Ffunctional_programming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkfmapf123%2Ffunctional_programming/lists"}