{"id":15036076,"url":"https://github.com/moonad-dotnet/moonad","last_synced_at":"2025-04-09T23:20:58.187Z","repository":{"id":213894740,"uuid":"735200798","full_name":"moonad-dotnet/moonad","owner":"moonad-dotnet","description":"A simple F#'s monads port for C#.","archived":false,"fork":false,"pushed_at":"2024-03-30T20:43:12.000Z","size":209,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-03-31T20:44:47.285Z","etag":null,"topics":["csharp","csharp-library","functional-programming","monad","monads","result","result-type"],"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/moonad-dotnet.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}},"created_at":"2023-12-24T03:05:56.000Z","updated_at":"2024-04-15T01:24:15.346Z","dependencies_parsed_at":"2024-04-15T01:24:13.266Z","dependency_job_id":"d9f0e268-6ad9-48c8-b11a-63dca43907dd","html_url":"https://github.com/moonad-dotnet/moonad","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"021fb598b6cd75e510c578ddbd7b76fd40ea4030"},"previous_names":["2hit-io/moonad"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonad-dotnet%2Fmoonad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonad-dotnet%2Fmoonad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonad-dotnet%2Fmoonad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moonad-dotnet%2Fmoonad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moonad-dotnet","download_url":"https://codeload.github.com/moonad-dotnet/moonad/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248126355,"owners_count":21051908,"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","csharp-library","functional-programming","monad","monads","result","result-type"],"created_at":"2024-09-24T20:30:03.446Z","updated_at":"2025-04-09T23:20:58.160Z","avatar_url":"https://github.com/moonad-dotnet.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Moonad\n\n![Version](https://img.shields.io/nuget/v/moonad?label=version\u0026color=029632) ![Tests](https://img.shields.io/github/actions/workflow/status/moonad-dotnet/moonad/dotnet.yml?logo=github\u0026label=tests\u0026color=029632) ![Nuget](https://img.shields.io/nuget/dt/moonad?logo=nuget\u0026label=downloads\u0026color=029632)\n\n\nA simple F#'s monads port for C#.\n\nThis library contains the main F#'s monads found on FSharp.Core lib written in, and adapted for, C#. Check the docs at [Moonad.NET](https://moonad.net).\n\n## Installing\nThe project's package can be found on [Nuget](https://nuget.org/packages/moonad) and installed by your IDE or shell as following:\n\n```shell\ndotnet add package Moonad\n```\n\nor\n\n```shell\nPM\u003e Install-Package Moonad\n```\n\n### A Note on Null Reference Types\n\nSince our main goal is to protect the user from `NullReferenceException` we strongly recommend the use of [Nullable Reference Types](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-reference-types) on any project which uses this lib.\n\n## The Monads\n\nF# offers in it's core library four monads to help you to have more flexibility when working with primitives and also potential null occurrences. So this library do the same.\n\n### Choice\nAlso known as `Either` in some languages this monad offers you the possibility to choose one of two types to be hold by its instance.\n\nExample:\n\n```c#\npublic Choice\u003cint, string\u003e Choose(bool returnInt)\n{\n    if(returnInt)\n        return 1;\n\n    return \"This is a Choice!\";\n}\n```\n\n### Result\n\nA type to express the final state of a given processing revealing its success of failure and optionally carrying a value or an error.\n\nExample 1 - Success indicator:\n\n```c#\npublic Result Send(Message message)\n{\n    try\n    {\n       ... \n       return Result.Ok();\n    }\n    catch(Exception exc)\n    {\n        ...\n        return Result.Error();\n    }\n}\n```\n\nExample 2 - Value and error returning:\n\n```c#\npublic Result\u003cUser, IError\u003e Create(...)\n{\n    //When a guard clause is actioned\n    return new EmptyUserNameError();\n\n    //When all is valid\n    return new User(...);\n}\n```\n\n### Option\n\nThis monad, also known as `Maybe`, has as its goal preventing the `NullReferenceException` by notifying the existence or absense of a value. Once a potentially null, or simply absent, value is converted to Option it's evaluated to a `Some` instance, which carry the value, or a `None` instance, which replaces the `null` and let the client works as `null` doesn't exists.\n\nExample 1 - Preventing null from a 3rd party lib:\n```c#\n//lib.Method returns a string\n\nvar option = lib.Method().ToOption();\n//The ToOption method will turn a null value into a None instance.\n\nif(option.IsSome)\n    Console.WriteLine($\"Returned value: {option}\");\nif(option.IsNone)\n    Console.WriteLine($\"No returned value.\");\n```\n\nExample 2 - Creating an Option explicitly:\n```c#\npublic Option\u003cint\u003e ReturnWhenGreaterThanZero(int input) =\u003e\n    input \u003e 0 ? input : Option.None\u003cT\u003e;\n```\n\n### ValueOption\nIt has the very same concept as Option but is intended to use with value types to be faster in performance critical scenarios.\n\nExample 1 - Preventing null from a 3rd party lib:\n```c#\n//lib.Method returns a nullable int\n\nvar option = lib.Method().ToValueOption();\n//The ToOption method will turn a null value into a None instance.\n\nif(option.IsSome)\n    Console.WriteLine($\"Returned value: {option}\");\nif(option.IsNone)\n    Console.WriteLine($\"No returned value.\");\n```\n\nExample 2 - Creating an Option explicitly:\n```c#\npublic ValueOption\u003cint\u003e ReturnWhenGreaterThanZero(int input) =\u003e\n    input \u003e 0 ? input : ValueOption\u003cint\u003e.None;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonad-dotnet%2Fmoonad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoonad-dotnet%2Fmoonad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoonad-dotnet%2Fmoonad/lists"}