{"id":20449541,"url":"https://github.com/vulcand/predicate","last_synced_at":"2025-05-15T01:07:32.945Z","repository":{"id":22086181,"uuid":"25415786","full_name":"vulcand/predicate","owner":"vulcand","description":"Library for creating predicate mini-languages in Go","archived":false,"fork":false,"pushed_at":"2025-03-25T02:11:34.000Z","size":50,"stargazers_count":99,"open_issues_count":2,"forks_count":18,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-04-15T01:57:44.886Z","etag":null,"topics":["go","golang","mini-language","predicate"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/vulcand/predicate#section-readme","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vulcand.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,"zenodo":null}},"created_at":"2014-10-19T02:29:19.000Z","updated_at":"2025-03-25T02:11:38.000Z","dependencies_parsed_at":"2024-11-15T10:42:32.997Z","dependency_job_id":"f17e0422-76e6-48b1-b604-6514833876f2","html_url":"https://github.com/vulcand/predicate","commit_stats":null,"previous_names":["mailgun/predicate"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vulcand%2Fpredicate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vulcand%2Fpredicate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vulcand%2Fpredicate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vulcand%2Fpredicate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vulcand","download_url":"https://codeload.github.com/vulcand/predicate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254254041,"owners_count":22039792,"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":["go","golang","mini-language","predicate"],"created_at":"2024-11-15T10:42:27.449Z","updated_at":"2025-05-15T01:07:27.932Z","avatar_url":"https://github.com/vulcand.png","language":"Go","readme":"# Predicate\n\nPredicate package used to create interpreted mini languages with Go syntax - mostly to define\nvarious predicates for configuration, e.g. \n\n```\nLatency() \u003e 40 || ErrorRate() \u003e 0.5.\n```\n\nHere's an example of fully functional predicate language to deal with division remainders:\n\n```go\npackage main\n\nimport (\n  \"log\"\n\t\n  \"github.com/vulcand/predicate\"\n)\n\n// takes number and returns true or false\ntype numberPredicate func(v int) bool\n\n// Converts one number to another\ntype numberMapper func(v int) int\n\n// Function that creates predicate to test if the remainder is 0\nfunc divisibleBy(divisor int) numberPredicate {\n     return func(v int) bool {\n         return v%divisor == 0\n     }\n}\n\n// Function - logical operator AND that combines predicates\nfunc numberAND(a, b numberPredicate) numberPredicate {\n    return func(v int) bool {\n        return a(v) \u0026\u0026 b(v)\n    }\n}\n\nfunc main(){\n    // Create a new parser and define the supported operators and methods\n    p, err := predicate.NewParser(predicate.Def{\n        Operators: predicate.Operators{\n           AND: numberAND,\n        },\n        Functions: map[string]interface{}{\n            \"DivisibleBy\": divisibleBy,\n        },\n    })\n\n    pr, err := p.Parse(\"DivisibleBy(2) \u0026\u0026 DivisibleBy(3)\")\n    if err != nil {\n\t\tlog.Fatalf(\"Error: %v\", err)\n\t}\n\n\tfmt.Println(pr.(numberPredicate)(2)) // false\n\tfmt.Println(pr.(numberPredicate)(3)) // false\n\tfmt.Println(pr.(numberPredicate)(6)) // true\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvulcand%2Fpredicate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvulcand%2Fpredicate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvulcand%2Fpredicate/lists"}