{"id":31826018,"url":"https://github.com/joshua-light/pocket.net","last_synced_at":"2025-10-11T16:52:14.369Z","repository":{"id":65413908,"uuid":"135206911","full_name":"joshua-light/pocket.net","owner":"joshua-light","description":"A tiny pocket of useful stuff for .NET.","archived":false,"fork":false,"pushed_at":"2020-11-16T09:37:14.000Z","size":586,"stargazers_count":10,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-06T00:58:24.797Z","etag":null,"topics":["common","declarative","extensions","fluent","linq"],"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/joshua-light.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":"2018-05-28T20:36:23.000Z","updated_at":"2024-04-01T22:13:53.000Z","dependencies_parsed_at":"2023-01-23T10:55:05.526Z","dependency_job_id":null,"html_url":"https://github.com/joshua-light/pocket.net","commit_stats":null,"previous_names":["joshualight/pocket.common","joshualight/pocket.net"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/joshua-light/pocket.net","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshua-light%2Fpocket.net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshua-light%2Fpocket.net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshua-light%2Fpocket.net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshua-light%2Fpocket.net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshua-light","download_url":"https://codeload.github.com/joshua-light/pocket.net/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshua-light%2Fpocket.net/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007980,"owners_count":26084369,"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-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["common","declarative","extensions","fluent","linq"],"created_at":"2025-10-11T16:52:04.133Z","updated_at":"2025-10-11T16:52:14.361Z","avatar_url":"https://github.com/joshua-light.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pocket\n\n![Build](https://github.com/JoshuaLight/pocket.net/workflows/Build/badge.svg)\n[![NuGet](https://img.shields.io/nuget/v/Pocket.svg)](https://www.nuget.org/packages/Pocket)\n\n_A tiny pocket of useful stuff for .NET._\n\n## Extensions\n\n### Collections\n\n#### `AddRange`\n\nAdds a range of items to the `ICollection\u003cT\u003e` instance (pretty common extension that is missing in standard library).\n\n```cs\nICollection\u003cint\u003e numbersA = { 1, 2, 3 };\nIEnumerable\u003cint\u003e numbersB = { 4, 5, 6 };\n\nnumbersA.AddRange(numbersB);\n\nConsole.WriteLine(numbersA.AsString()); // Prints \"[1, 2, 3, 4, 5, 6]\".\n```\n\n### Dictionary\n\n#### `One`\n\nRepresents a consistent access to dictionary elements in four different ways using fluent sentences, starting with `One`. Each way represents a reaction to situation, when key is missing.\n\nThese reactions are:\n\na) throw a `KeyNotFoundException` with specified message:\n```cs\nvar writers = new Dictionary\u003cstring, string\u003e\n{\n    { \"Hermann\": \"Hesse\" },\n};\n\nvar x = writers.One(withKey: \"Thomas\").OrThrow(withMessage: \"Couldn't find `Thomas`.\");\n// `KeyNotFoundException` is thrown.\n```\n\nb) return `default(TValue)`:\n```cs\nvar writers = new Dictionary\u003cstring, string\u003e\n{\n    { \"Hermann\": \"Hesse\" },\n};\n\nvar x = writers.One(withKey: \"Thomas\").OrDefault();\nConsole.WriteLine(x ?? \"null\"); // Prints `null`.\n```\n\nc) return specified value:\n```cs\nvar writers = new Dictionary\u003cstring, string\u003e\n{\n    { \"Hermann\": \"Hesse\" },\n};\n\nvar x = writers.One(withKey: \"Thomas\").Or(\"\");\nvar y = writers.One(withKey: \"Thomas\").Or(() =\u003e \"\");\nConsole.WriteLine(x); // Prints `\"\"`.\nConsole.WriteLine(y); // Prints `\"\"`.\n```\n\nd) return specified value and also write it to dictionary:\n```cs\nvar writers = new Dictionary\u003cstring, string\u003e\n{\n    { \"Hermann\": \"Hesse\" },\n};\n\nvar x = writers.One(withKey: \"Thomas\").OrNew(\"Mann\");\nvar y = writers[\"Thomas\"];\nConsole.WriteLine(x); // Prints `\"Mann\"`.\nConsole.WriteLine(y); // Prints `\"Mann\"`.\n```\n\n### Enumerable\n\n#### `OrEmpty`\n\nReturns `Enumerable.Empty\u003cT\u003e` sequence if current is `null`. This method can be used\nas a more fluent alternative to `x ?? Enumerable.Empty\u003cT\u003e`.\n\n```cs\nIEnumerable\u003cint\u003e x = null;\n\nConsole.WriteLine(x.OrEmpty()); // Prints [].\n```\n\n#### `Each`\n\nExecutes specified action on each item of the sequence. This can be useful when you want,\nfor example, to print items in the middle of LINQ.\n\n``` cs\nEnumerable\n    .Range(1, 10)\n    .Where(x =\u003e x % 2 == 0)\n    .Each(Console.Write)\n    .Select(x =\u003e x * x)\n    .ToList(); // Prints \"246810\".\n```\n\n#### `ForEach`\n\nExecutes specified action on each item of the sequence, but doesn't return anything.\n\nThis method is similar to `ForEach` from `List`.\n\n``` cs\nEnumerable\n    .Range(0, 10)\n    .Where(x =\u003e x % 2 == 0)\n    .ForEach(Console.Write); // Prints \"246810\".\n```\n\n#### `MinBy`\n\nTakes first object from the sequence that has minimum value, provided by specified selector function.\n\nThis method works in same way as LINQ `Min` but instead of value returns the object, not the minimum value it holds.\n\n``` cs\nstruct Point\n{\n    public readonly int X;\n    public readonly int Y;\n\n    public Point(int x, int y) =\u003e\n        (X, Y) = (x, y)\n}\n\n// `point` holds not an `int`, but `Point`.\nvar point = Enumerable\n    .Range(0, 10)\n    .Select(x =\u003e new Point(x, x))\n    .MinBy(p =\u003e p.X)\n\nConsole.WriteLine($\"{point.X}, {point.Y}\") // Prints \"0, 0\".\n```\n\n#### `MaxBy`\n\nWorks in similar way as `MinBy`, but returns an object with maximum value.\n\n#### `IsNullOrEmpty`\n\nChecks whether sequence is either `null` or contains no elements.\n\n``` cs\nIEnumerable\u003cint\u003e a;\n\na = Enumerable.Range(0, 10);\nConsole.WriteLine(numbers.IsNullOrEmpty()); // Prints \"false\".\n\na = null;\nConsole.WriteLine(numbers.IsNullOrEmpty()); // Prints \"true\".\n\na = Enumerable.Empty\u003cint\u003e();\nConsole.WriteLine(numbers.IsNullOrEmpty()); // Prints \"true\".\n```\n\n#### `IsEmpty`\n\nChecks whether sequence contains no elements.\n\n``` cs\nvar sequence = Enumerable.Empty\u003cint\u003e();\n\nConsole.WriteLine(sequence.IsEmpty()); // Prints \"true\".\n```\n\nTODO\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshua-light%2Fpocket.net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshua-light%2Fpocket.net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshua-light%2Fpocket.net/lists"}