{"id":21850591,"url":"https://github.com/freakwill/fcool","last_synced_at":"2025-03-21T17:49:02.726Z","repository":{"id":57428876,"uuid":"100145340","full_name":"Freakwill/fcool","owner":"Freakwill","description":"A cool tool for functional programming","archived":false,"fork":false,"pushed_at":"2018-01-20T09:21:21.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-26T18:53:45.410Z","etag":null,"topics":["functional-programming","memoize","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/Freakwill.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}},"created_at":"2017-08-13T00:52:45.000Z","updated_at":"2018-06-09T09:47:37.000Z","dependencies_parsed_at":"2022-08-26T03:43:10.532Z","dependency_job_id":null,"html_url":"https://github.com/Freakwill/fcool","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/Freakwill%2Ffcool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Ffcool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Ffcool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Freakwill%2Ffcool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Freakwill","download_url":"https://codeload.github.com/Freakwill/fcool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244843184,"owners_count":20519778,"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","memoize","python"],"created_at":"2024-11-28T00:18:18.903Z","updated_at":"2025-03-21T17:49:02.702Z","avatar_url":"https://github.com/Freakwill.png","language":"Python","readme":"Introduction\n=============\n\nAbstract\n----------\nA cool tool for functional programming. Operating Functions as in math. Type testing is implemented in an awsome way as well as memoizing.\n\nKeywords\n----------\nFunctional Programming, Type Testing\n\nFeature:\n\n    1. function with domain, the domain can be used to type testing\n    2. operator on functions, for example, f + g: x -\u003e f(x) + g(x) where f, g,  f+g are functions\n    3. to glue functions with glue function or method that can be used to define piecewise functions\n    4. no 3rd part requirement \n    5. implement memoization in oo way.\n    6. use MathFunction for math functions where keyword arguments are deprecated.  (new in this version)\n\n\nContent\n=========\n\nClasses\n\n    BaseFunction -\u003e Type (or Domain), Function\n    BaseFunction: func: function (or number)\n    Function: func,\n              domain: Type, the definition domain of func\n\nFunctions\n\n    Interval(a:num, b:num) -\u003e Type\n    restrict(t:Type) -\u003e decorator(f:function -\u003e Function(f, t))\n\nConstants\n\n    TURE, FALSE(Type) represent universal set, empty set\n\nGrammar\n=========\n\nBasic grammar\n-------------\n\nimport:\n\n```python\nimport fcool (or from fcool import *)\n```\n\nDefine Function with domain:\n\n```python\nF = Function(lambda x:x, Type(lambda x:x\u003e2))\nF(3)\n```\n\nOperators on Functions:\n\n```python\n    (F + F)(3)\n    (F * F)(4)\n    (2 * F)(3)\n```\n\n2D Functions and Types:\n\n```python\n    f = 3     # or lambda x,y: 3\n    g = lambda x,y: 2/x\n    t = Type(lambda x:x\u003c5 and isinstance(x, int)) * TRUE  # define type(domain) and functions on it\n        \u003c=\u003e Type(lambda x, y:x\u003c5) \u0026 Type(lambda x, y:isinstance(x, int))\n    G = Function(g, t)\n    F = Function(f, t)\n```\n\n*Memoize (the coolest feature of the new version)*:\n\n```python   \n   f.memoize()    # f is the object of BaseFunction, similar to toolz.memoize(f)\n   f.unmemoize()  # prohibit to use memo (memo is not deleted)\n   f.del_memo()   # just clear the memo, will update the memo in next time\n   f.forget()     # f.del_memo() and f.unmemoize()\n```\n\nAdvanced Grammar\n----------------\n\nGlue Functions:\n\n```python    print(G.glue(F)(3,4), glue(G, F)(3,4))    # glue functions\n\n    ID = Function(lambda x:x)\n    print(ID.compose(F)(3,4))      # composition\n```\n\nType testing with restrict decorator:\n\n```python\n    @restrict(Interval(1,2))       # restriction decorator\n    def f(x):\n        return x\n\n    print(f(1))\n    try:\n        print(f(3))\n    except Exception as ex:\n        print(ex)\n\n    G=Function(lambda x:x)\n    print(G(3))\n    G = G | Interval(1,2)           # restriction method   \n    print(G(3))\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreakwill%2Ffcool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreakwill%2Ffcool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreakwill%2Ffcool/lists"}