{"id":29637350,"url":"https://github.com/pepelev/comparation","last_synced_at":"2026-03-08T19:37:46.067Z","repository":{"id":45966023,"uuid":"350454854","full_name":"pepelev/Comparation","owner":"pepelev","description":"Comparation is tiny library for work with equality and order","archived":false,"fork":false,"pushed_at":"2021-11-23T21:03:36.000Z","size":77,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-31T07:39:24.312Z","etag":null,"topics":["c-sharp","csharp","dotnet","equality","order"],"latest_commit_sha":null,"homepage":"","language":"C#","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/pepelev.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":"2021-03-22T18:50:52.000Z","updated_at":"2023-02-15T19:01:09.000Z","dependencies_parsed_at":"2022-09-09T05:51:14.187Z","dependency_job_id":null,"html_url":"https://github.com/pepelev/Comparation","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/pepelev/Comparation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepelev%2FComparation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepelev%2FComparation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepelev%2FComparation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepelev%2FComparation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pepelev","download_url":"https://codeload.github.com/pepelev/Comparation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pepelev%2FComparation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266353222,"owners_count":23915919,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c-sharp","csharp","dotnet","equality","order"],"created_at":"2025-07-21T18:37:19.992Z","updated_at":"2026-03-08T19:37:46.038Z","avatar_url":"https://github.com/pepelev.png","language":"C#","readme":"# Comparation\n\n__Comparation__ is tiny library for work with equality and ordering.\n\n![Comparation](logo.svg)\n\n## Installation\n\nInstall [NuGet package](https://www.nuget.org/packages/Comparation/) using Package Manager\n\n```\nInstall-Package Comparation\n```\n\n## Equality\n\nWith __Comparation__ you will be able to define custom equality in just few lines\n\n```csharp\nusing System;\nusing System.Collections.Generic;\nusing Comparation;\n\nIEqualityComparer\u003cVersion\u003e equality = Equality.Of\u003cVersion\u003e()\n    .By(version =\u003e version.Major)\n    .AndBy(version =\u003e version.Minor);\n\nequality.Equals(new Version(2, 17, 4), new Version(2, 17, 5)); // returns true\nequality.Equals(new Version(2, 19, 4), new Version(2, 17, 4)); // returns false, Minor components are different\n```\n\nThis is useful when you need to override equality in your own way or define it for a library type\nthat does not provide proper `Equals` and `GetHashCode` methods.\n\nYou can also pass equality into collections\n\n```csharp\nvar equality = Equality.Of\u003cstring\u003e().By(@string =\u003e @string.Length);\n\nvar pets = new HashSet\u003cstring\u003e(equality);\npets.Add(\"Dog\");\npets.Add(\"Cat\"); // Bad day for Cat ;), pets already contain element with length 3\npets.Add(\"Turtle\");\n\nstring.Join(\", \", pets); // returns \"Dog, Turtle\"\n```\n\nAnd finally you can easily compare entire collections\n\n```csharp\nIEqualityComparer\u003cIReadOnlyCollection\u003cstring\u003e\u003e equality = Equality.Of\u003cstring\u003e().Collection();\n\nvar required = new[] {\"engine\", \"body\", \"door\", \"door\", \"windshield\"};\nvar inventory = new[] {\"body\", \"door\", \"windshield\", \"engine\"};\nequality.Equals(required, inventory); // returns false, second door is missing\n\nvar deliveries = new[] {\"body\", \"door\", \"engine\", \"windshield\", \"door\"};\nequality.Equals(required, deliveries); // returns true\n```\n\n## Order\n\nOrder is defined very similar to equality\n\n```csharp\nIComparer\u003cstring\u003e order = Order.Of\u003cstring\u003e()\n    .By(@string =\u003e @string[0])\n    .ThenBy(@string =\u003e @string.Length);\n\norder.Compare(\"Apple\", \"Banana\"); // returns -1, (Apple less than Banana) by first letter\norder.Compare(\"Brown\", \"Bohr\"); // returns 1, (Brown greater than Bohr) by length since first letters are same\norder.Compare(\"Cat\", \"Can\"); // returns 0, (Cat equal to Can) by first letter and length\n```\n\nOrder is useful when you need to customize sorting criteria at run time.\n\nDo you want to reverse order? Easy - use `.Invert()`\n\n```csharp\nvar ascendingOrder = Order.Of\u003cint\u003e().Default;\nvar descendingOrder = ascendingOrder.Invert();\n\nvar numbers = new List\u003cint\u003e {7, 9, 16, 3};\nnumbers.Sort(descendingOrder); // returns 16, 9, 7, 3\n```\n\nWith order you can compare sequences like this\n\n```csharp\nIComparer\u003cIEnumerable\u003cint\u003e\u003e order = Order.Of\u003cint\u003e().Sequence();\n\nvar myLuckyNumbers = new[] {1, 7, 32, 14, 4};\nvar lotteryNumbers = new[] {1, 7, 32, 28, 4};\norder.Compare(myNumbers, lotteryNumbers); // returns -1, (14 is less than 28)\norder.Compare(new[] {1, 2, 3}, new[] {1, 2}); // returns 1, sequences match by prefix, but first is longer\n```\n\nOr just get `Max()` value from two\n\n```csharp\nvar order = Order.Of\u003cint\u003e().Default;\n\norder.Max(19, 7); // returns 19\norder.Min(19, 7); // returns 7\n```\n\nYou can also benefit from `Sign()` extension method to avoid mind-blowing work with `-1`, `0` and `1`[^1]\n\n```csharp\nvar myLuckyNumbers = new[] {1, 7, 32, 14, 4};\nvar lotteryNumbers = new[] {1, 7, 32, 28, 4};\norder.Sign(myNumbers, lotteryNumbers); // returns Sign.Less, (14 is less than 28)\norder.Sign(new[] {1, 2, 3}, new[] {1, 2}); // returns Sign.Greater, sequences match by prefix, but first is longer\n```\n\n[^1]: Actually, negative, zero, and positive https://docs.microsoft.com/en-us/dotnet/api/system.collections.icomparer.compare","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpepelev%2Fcomparation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpepelev%2Fcomparation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpepelev%2Fcomparation/lists"}