{"id":15168591,"url":"https://github.com/ciavash/patternmatching","last_synced_at":"2025-10-01T00:32:20.962Z","repository":{"id":147482098,"uuid":"421038753","full_name":"CIAvash/PatternMatching","owner":"CIAvash","description":"A Raku module for pattern matching","archived":true,"fork":false,"pushed_at":"2021-10-25T19:27:42.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-30T17:36:55.875Z","etag":null,"topics":["functional-programming","library","module","pattern-matching","raku","raku-module","rakulang"],"latest_commit_sha":null,"homepage":"https://codeberg.org/CIAvash/PatternMatching","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CIAvash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2021-10-25T13:37:14.000Z","updated_at":"2024-03-30T12:39:35.000Z","dependencies_parsed_at":"2023-07-24T21:18:09.073Z","dependency_job_id":null,"html_url":"https://github.com/CIAvash/PatternMatching","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"e94890f1c063c3b6ab84fb2478118fe379bfb680"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIAvash%2FPatternMatching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIAvash%2FPatternMatching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIAvash%2FPatternMatching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CIAvash%2FPatternMatching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CIAvash","download_url":"https://codeload.github.com/CIAvash/PatternMatching/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234803487,"owners_count":18889263,"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","library","module","pattern-matching","raku","raku-module","rakulang"],"created_at":"2024-09-27T06:23:20.651Z","updated_at":"2025-10-01T00:32:20.678Z","avatar_url":"https://github.com/CIAvash.png","language":"Raku","readme":"NAME\n====\n\nPatternMatching\n\nDESCRIPTION\n===========\n\nPatternMatching is a [Raku](https://www.raku-lang.ir/en/) module for pattern matching.\n\nIt provides `match_pattern` infix operator and `┇` as an alias for it. It accepts a topic and a list of patterns(`Code`s) and can be used like `$topic match_pattern -\u003e $some_pattern {...}`.\n\nIf the topic doesn't match any of the patterns, a `Failure` containing the `X::PatternMatching::MatchFailed` exception will be returned.\n\nInfo for `┇`:\n\n  * Code: U+2507\n\n  * Name: BOX DRAWINGS HEAVY TRIPLE DASH VERTICAL\n\nSYNOPSIS\n========\n\n```raku\nuse PatternMatching:auth\u003czef:CIAvash\u003e;\n\nclass C { has $.a = 'attribute' }\n\nmy @a = 1, [2, 3], 'a', \u003cb c\u003e, :d(4), :e[5, 6], 10, 'f', 'g', 'h', 20,\n        C.new, PatternMatching, :g(8, 2), [7, 8, 9];\n\nmy @b = @a.map: * match_pattern\n          -\u003e 10 { 'ten' },\n          -\u003e Int $a where * \u003e 10 { 'twenty' },\n          -\u003e Int $a { $a + 2 },\n          -\u003e Str $a where any \u003cf g h\u003e { 'f or g or h' },\n          -\u003e Str $a { $a.succ },\n          -\u003e C (:$a) { $a },\n          -\u003e @ (Str $a, Str $b) { join ' | ', $a, $b },\n          -\u003e @ (Int $a, Int $b) { $a + $b },\n          -\u003e @ (Int $a, *@b where .all ~~ Int) { [+] $a, |@b },\n          -\u003e Pair (:key($a), :value([$b, $c])) { \"$a: {$b + $c}\" },\n          -\u003e Hash() (:$g ($a, $b)) { \"$g: {$a + $b}\" },\n          -\u003e Pair $pair { $pair.kv.join: ': ' },\n          -\u003e | { 'default' }\n\nput @b.raku;\n=output [3, 5, \"b\", \"b | c\", \"d: 4\", \"e: 11\", \"ten\", \"f or g or h\", \"f or g or h\", \"f or g or h\", \"twenty\", \"attribute\", \"default\", \"g: 10\", 24]␤\n\nmy @c = @a.map: * ┇\n          -\u003e @ (Str $a, Str $b) { join ' | ', $a, $b },\n          -\u003e @ (Int $a, Int $b) { $a + $b },\n          -\u003e | { 'default' }\n\nput @c.raku;\n=output [\"default\", 5, \"default\", \"b | c\", \"default\", \"default\", \"default\", \"default\", \"default\", \"default\", \"default\", \"default\", \"default\", \"default\", \"default\"]␤\n\nfor @a {\n    .put with .\u0026[match_pattern]:\n                -\u003e 10 { 'ten' },\n                -\u003e Int $a where * \u003e 10 { 'twenty' },\n                -\u003e Int $a { $a + 2 },\n                -\u003e Str $a where any \u003cf g h\u003e { 'f or g or h' },\n                -\u003e Str $a { $a.succ },\n                -\u003e C (:$a) { $a };\n                -\u003e @ (Str $a, Str $b) { join ' | ', $a, $b },\n                -\u003e @ (Int $a, Int $b) { $a + $b },\n                -\u003e @ (Int $a, *@b where .all ~~ Int) { [+] $a, |@b },\n                -\u003e Pair (:key($a), :value([$b, $c])) { \"$a: {$b + $c}\" },\n                -\u003e Hash() (:$g ($a, $b)) { \"$g: {$a + $b}\" },\n                -\u003e Pair $pair { $pair.kv.join: ': ' },\n}\n```\n\nINSTALLATION\n============\n\nYou need to have [Raku](https://www.raku-lang.ir/en) and [zef](https://github.com/ugexe/zef), then run:\n\n```console\nzef install --/test \"PatternMatching:auth\u003czef:CIAvash\u003e\"\n```\n\nor if you have cloned the repo:\n\n```console\nzef install .\n```\n\nTESTING\n=======\n\n```console\nprove -ve 'raku -I.' --ext rakutest\n```\n\nSUBS\n====\n\n## sub infix:\u003cmatch_pattern\u003e\n\n```raku\nsub infix:\u003cmatch_pattern\u003e(\n    $topic,\n    *@functions where { ... }\n) returns Mu\n```\n\nMatches `topic` against a list of patterns(functions).\n\nReturns `Failure`(`X::PatternMatching::MatchFailed`) when no pattern is matched.\n\n## sub infix:\u003c┇\u003e\n\n```raku\n\u0026infix:\u003c┇\u003e = \u0026[match_pattern]\n```\n\nAlias for `match_pattern`\n\nERRORS\n======\n\nIf the topic doesn't match any of the patterns, a `Failure` containing the `X::PatternMatching::MatchFailed` exception will be returned.\n\nREPOSITORY\n==========\n\n[https://github.com/CIAvash/PatternMatching/](https://github.com/CIAvash/PatternMatching/)\n\nBUG\n===\n\n[https://github.com/CIAvash/PatternMatching/issues](https://github.com/CIAvash/PatternMatching/issues)\n\nAUTHOR\n======\n\nSiavash Askari Nasr - [https://www.ciavash.name](https://www.ciavash.name)\n\nCOPYRIGHT\n=========\n\nCopyright © 2021 Siavash Askari Nasr\n\nLICENSE\n=======\n\nThis file is part of PatternMatching.\n\nPatternMatching is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at yoption) any later version.\n\nPatternMatching is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License along with PatternMatching. If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fciavash%2Fpatternmatching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fciavash%2Fpatternmatching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fciavash%2Fpatternmatching/lists"}