{"id":15394254,"url":"https://github.com/xyproto/purefunction","last_synced_at":"2025-04-15T23:53:13.735Z","repository":{"id":136551050,"uuid":"149764160","full_name":"xyproto/purefunction","owner":"xyproto","description":"Given a Go source code file, find all known pure functions","archived":false,"fork":false,"pushed_at":"2024-10-11T14:45:36.000Z","size":1305,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-12T13:22:49.106Z","etag":null,"topics":["optimization-tools","static-code-analysis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyproto.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":"2018-09-21T13:01:21.000Z","updated_at":"2024-10-11T14:45:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"042cecd1-efd9-4645-97f0-2696b3d0d7de","html_url":"https://github.com/xyproto/purefunction","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.07407407407407407,"last_synced_commit":"b9ba3778c763512b864e0c539131a64ea8496356"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fpurefunction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fpurefunction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fpurefunction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Fpurefunction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyproto","download_url":"https://codeload.github.com/xyproto/purefunction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173061,"owners_count":21224481,"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":["optimization-tools","static-code-analysis"],"created_at":"2024-10-01T15:22:49.376Z","updated_at":"2025-04-15T23:53:13.720Z","avatar_url":"https://github.com/xyproto.png","language":"Go","readme":"# purefunction [![GoDoc](https://godoc.org/github.com/xyproto/purefunction?status.svg)](http://godoc.org/github.com/xyproto/purefunction) [![License](http://img.shields.io/badge/license-BSD-green.svg?style=flat)](https://raw.githubusercontent.com/xyproto/purefunction/master/LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/xyproto/purefunction)](https://goreportcard.com/report/github.com/xyproto/purefunction)\n\nGiven a Go source file, find the names of all functions that are known to be pure.\n\nA \"pure function\" for this module is, a function that:\n\n* Only calls functions that are known to be pure, if any.\n* Does not read or write to any global variables.\n* Does not have pointers or slices as function arguments.\n* Does not read or write to any memory location using pointers.\n* Ideally: Always returns the same answer, given the same input, but this is hard to test for (ref. halting problem).\n\n### Examples of pure functions\n\nExample of a pure function:\n\n```go\nfunc add(a, b int) int {\n    return a + b\n}\n```\n\nAnother example of a pure function (even though it is a \"method\"):\n\n```go\nfunc (c *Config) Add(a, b int) int {\n    return a + b\n}\n```\n\n### Features and limitations\n\n* Functions are filtered out if they have non-pure indicators. The ones that are left are considered pure.\n* Functions that read from a file, read from the keyboard, uses randomness or the system time are not pure, but may be detected as such.\n\n### Approach\n\n* Uses [`go/ast`](http://golang.org/pkg/go/ast) extensively.\n\n### Memoization\n\nPure functions, like the `fibonacci` function, has great potential for optimization by memoization.\n\nBenchmark output for \"fibonacci\" vs \"memoized fibonacci\":\n\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/xyproto/purefunction/example\nBenchmarkFib10-8                   30586             38894 ns/op\nBenchmarkFibMemoized-8          84117813                14.2 ns/op\nPASS\nok      github.com/xyproto/purefunction/example 2.798s\n```\n\nSee issue #1.\n\n### Requirements\n\n* Go 1.10 or later.\n\n### General info\n\n* Version: 1.0.3\n* License: BSD-3\n* Author: Alexander F. Rødseth \u0026lt;xyproto@archlinux.org\u0026gt;\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fpurefunction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyproto%2Fpurefunction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Fpurefunction/lists"}