{"id":18898422,"url":"https://github.com/hychen/harrow","last_synced_at":"2025-07-09T22:33:29.467Z","repository":{"id":8307504,"uuid":"9852592","full_name":"hychen/harrow","owner":"hychen","description":"Using Haskell Arrow in Python","archived":false,"fork":false,"pushed_at":"2013-06-01T13:57:50.000Z","size":163,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-15T02:38:27.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/hychen.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":"2013-05-04T10:34:30.000Z","updated_at":"2021-04-19T20:49:19.000Z","dependencies_parsed_at":"2022-08-07T02:01:33.478Z","dependency_job_id":null,"html_url":"https://github.com/hychen/harrow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hychen/harrow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hychen%2Fharrow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hychen%2Fharrow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hychen%2Fharrow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hychen%2Fharrow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hychen","download_url":"https://codeload.github.com/hychen/harrow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hychen%2Fharrow/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264504613,"owners_count":23618830,"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-08T08:42:33.912Z","updated_at":"2025-07-09T22:33:29.446Z","avatar_url":"https://github.com/hychen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using Haskell Arrow in Python.\n\nI used to be an adventurer like you but then i took an arrow to the knee....\n\n## Forward pipeline\n\n```\nfrom harrow import arr\nplus1 = lambda n: n + 1\npow2 = lambda n: n * 2\n# pow2(plus1(0))\nproc = arr(plus1).to_a(pow2)\nprint proc(0) # result: 2\n# syntax sugar\nproc = arr(plus1) | arr(plus2)\nprint proc(0) # result: 2\n```\n\n## Backward pipeline\n```\nfrom harrow import arr\nplus1 = lambda n: n + 1\npow2 = lambda n: n * 2\n# plus1(pow2(0))\nproc = arr(plus1).from_a(pow2)\nprint proc(0) # result: 1\n```\n\n## syntax sugar of forward pipeline\n\n```\nproc = Arrow(lambda n:n+1) | Arrow(lambda n:n+2)\nprint proc(1)\n\n```\n\n## Feed \n\nThe input argument of a arrow or a pipeline can predefined by feed method.\n\n```\nfrom harrow import arr\nfrom harrow.arrows import Arrow\n# set acc\nproc = arr().feed(1)\nproc.post(lambda acc: acc+1)\nprint proc()\n# the result is 2\n# ------------------------------------------------------\nproc2 = Arrow(lambda n:n+1).to_a(Arrow(lambda n:n+2))\nproc2.feed(3)\nprint proc()\n# the result is 6\n```\n\n## Choice\n\nSend the nth component of the input through the argument arrow, and copy the rest unchanged to the output.\n\n```\nfrom harrow import arr\narr1 = arr()\nproc = arr1.choice(1, lambda n: n + 1)\nprint proc([1,2,3,4]) # result: [1, 3, 3, 4])\n```\n\n## Fanout\n\nsend the input to both argument arrows and combine their output.\n\n```\n\u003e\u003e\u003e from harrow import arr\n\u003e\u003e\u003e import urllib\n\u003e\u003e\u003e gpage = arr(urllib.urlopen, \"http://www.google.com\")\n\u003e\u003e\u003e ypage = arr(urllib.urlopen, \"http://www.yahoo.com\")\n\u003e\u003e\u003e prog = arr().fanout(gpage, ypage)\n# put all output of arrows into a list.\n\u003e\u003e\u003e print prog()\n[\u003caddinfourl at 140422088441440 whose fp = \u003csocket._fileobject object at 0x7fb692c21150\u003e\u003e, \u003caddinfourl at 140422122947576 whose fp = \u003csocket._fileobject object at 0x7fb692c1b750\u003e\u003e]\n```\n\n## Fanin\n\nSplit the input between the argument arrows and combine their output.\n\n```\n# construct 3 arrows.\narr_add1 = Arrow(lambda n: n+1).feed(1)\narr_add2 = Arrow(lambda n: n+2).feed(2)\narr_add3 = Arrow(lambda n: n+3).feed(3)\n# construct a arrow that find first number in input is bigger than 3.\nprog = Arrow().fanin(lambda e: e \u003e 3, arr_add1, arr_add2, arr_add3)\n# the result is 4.\n```\n\n## Parallel\n\nSplit the input between the two argument arrows and combine their output.\n\n```\nf = lambda n: n+1\ng = lambda n: n+2\nprog =  arr().parallel(f,g)\nprog.post(list)\n# compute f(1) and g(1) and combine the result.\nprint prog([1,2])\n```\n\n### Looping - Until\n\nRepeat function until the its input argument satisfy the termination condition.\n\n```\ndef append1(lst):\n    lst.append(1)\n    return lst\n            \nproc = Arrow(append1).until(lambda acc: len(acc) == 10)\n# [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\nprint proc([])\n```\n\n### Looping - Times is Loop is Trace\n\n```\ndef append_idx(acc):\n    (idx, lst) = acc\n    lst.append(idx)\n    return lst\n            \nproc = Arrow(append_idx).times(10)\n# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\nprint proc([])\n      \nproc =  Arrow(append_idx).loop(0, 10, 1)\n# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\nprint  proc([])\n\nproc = Arrow(append_idx).trace(lambda idx, acc: (idx == end, step + idx), start)\n# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\nprint  proc([])\n```\n\n## Reference\n- [Understanding Arrows](http://en.wikibooks.org/wiki/Haskell/Understanding_arrows)\n- [Circular Programming](http://www.haskell.org/haskellwiki/Circular_programming)\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhychen%2Fharrow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhychen%2Fharrow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhychen%2Fharrow/lists"}