{"id":19958545,"url":"https://github.com/badeend/nothing","last_synced_at":"2025-06-23T16:37:15.342Z","repository":{"id":233284444,"uuid":"786423812","full_name":"badeend/Nothing","owner":"badeend","description":"If you want to use `void` as a type parameter, but C# won't let you...","archived":false,"fork":false,"pushed_at":"2024-12-26T11:15:59.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T00:52:20.821Z","etag":null,"topics":["csharp","functional-programming","hack","unit"],"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/badeend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"badeend"}},"created_at":"2024-04-14T12:25:03.000Z","updated_at":"2024-12-26T11:15:17.000Z","dependencies_parsed_at":"2024-05-03T18:55:22.573Z","dependency_job_id":null,"html_url":"https://github.com/badeend/Nothing","commit_stats":null,"previous_names":["badeend/nothing"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badeend%2FNothing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badeend%2FNothing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badeend%2FNothing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badeend%2FNothing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badeend","download_url":"https://codeload.github.com/badeend/Nothing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241389166,"owners_count":19955107,"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":["csharp","functional-programming","hack","unit"],"created_at":"2024-11-13T01:43:34.544Z","updated_at":"2025-03-01T16:15:34.559Z","avatar_url":"https://github.com/badeend.png","language":"C#","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./docs/images/logo.png\" alt=\"Nothing\" width=\"300\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cem\u003eIf you want to use `void` as a type parameter, but C# won't let you...\u003c/em\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.nuget.org/packages/Badeend.Nothing\"\u003e\u003cimg src=\"https://img.shields.io/nuget/v/Badeend.Nothing\" alt=\"Nuget\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n`Badeend.Nothing` is struct that contains... well... nothing!\n\nAlso known as a \"unit\" type in Functional Programming parlance. \n\nIn C# this can be used in places where you have nothing to return, but `void` is not allowed. Most notably: generics.\n\n#### Example time!\n\nLet's assume there exists an interface that you want to implement:\n\n```cs\npublic interface IHandler\u003cT\u003e\n{\n  T Handle(MyInput input);\n}\n```\n\nIf your handler has nothing useful to return, then you would _want_ to write this:\n\n```cs\npublic class MyHandler : IHandler\u003cvoid\u003e // COMPILE ERROR!\n{\n  void Handle(MyInput input)\n  {\n    // (my implementation here)\n  }\n}\n```\n\nUnfortunately, \"Computer Says No\". C# won't let you.\n\nIf you're lucky enough to own that interface, you could decide to duplicate the interface and all related code: one for `IHandler`, and one for `IHandler\u003cT\u003e`.\n\nIf you're not able to change the interface or just don't feel like doing a bunch of unnecessary work; you could also change the type argument to `Nothing`:\n\n```cs\nusing Badeend;\n\npublic class MyHandler : IHandler\u003cNothing\u003e // \u003c--- Nothing to see here\n{\n  Nothing Handle(MyInput input)\n  {\n    // (my implementation here)\n\n    return Nothing.Value;\n  }\n}\n```\n\n## Installation\n\n[![NuGet Badeend.Nothing](https://img.shields.io/nuget/v/Badeend.Nothing?label=Badeend.Nothing)](https://www.nuget.org/packages/Badeend.Nothing)\n\n```sh\ndotnet add package Badeend.Nothing\n```\n\n## Fake `nothing` keyword\n\nDepending on how intensively you use this package, you might be interested in using `Badeend.Nothing.Keyword` globally, which exposes `nothing` as a top level field.\n\n```cs\nusing Badeend;\n\npublic class MyHandler : IHandler\u003cNothing\u003e\n{\n  Nothing Handle(MyInput input)\n  {\n    // (my implementation here)\n\n    return nothing; // \u003c--- Note the lowercase 'n'\n  }\n}\n```\n\nIn [C#10+](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive#global-modifier) this can be configured as follows:\n\n```cs\nglobal using static Badeend.Nothing.Keyword;\n```\n\nor:\n\n```xml\n\u003cItemGroup\u003e\n  \u003cUsing Include=\"Badeend.Nothing.Keyword\" Static=\"True\" /\u003e\n\u003c/ItemGroup\u003e\n```\n\n---\n\n### Shameless self-promotion\n\nMay I interest you in one of my other packages?\n\n- **[Badeend.ValueCollections](https://badeend.github.io/ValueCollections/)**: _Low overhead immutable collection types with structural equality._\n- **[Badeend.EnumClass](https://badeend.github.io/EnumClass/)**: _Discriminated unions for C# with exhaustiveness checking._\n- **[Badeend.Result](https://badeend.github.io/Result/)**: _For failures that are not exceptional: `Result\u003cT,E\u003e` for C#._\n- **[Badeend.Any](https://badeend.github.io/Any/)**: _Holds any value of any type, without boxing small structs (up to 8 bytes)._\n- **[Badeend.Nothing](https://github.com/badeend/Nothing)**: _If you want to use `void` as a type parameter, but C# won't let you._","funding_links":["https://github.com/sponsors/badeend"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadeend%2Fnothing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadeend%2Fnothing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadeend%2Fnothing/lists"}