{"id":19374660,"url":"https://github.com/jabez007/functionalcsharp","last_synced_at":"2025-04-13T20:11:25.666Z","repository":{"id":128393427,"uuid":"139631863","full_name":"jabez007/FunctionalCSharp","owner":"jabez007","description":"A library of static classes, extension methods, and classes that  apply functional techniques to C#.","archived":false,"fork":false,"pushed_at":"2019-01-16T23:47:42.000Z","size":107,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T04:18:25.415Z","etag":null,"topics":["c-sharp","csharp","functional-programming","lambda-calculus","lambda-expressions","lambda-functions","terraformed"],"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/jabez007.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2018-07-03T20:02:22.000Z","updated_at":"2024-07-30T21:39:39.000Z","dependencies_parsed_at":"2023-04-21T17:18:50.143Z","dependency_job_id":null,"html_url":"https://github.com/jabez007/FunctionalCSharp","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabez007%2FFunctionalCSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabez007%2FFunctionalCSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabez007%2FFunctionalCSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jabez007%2FFunctionalCSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jabez007","download_url":"https://codeload.github.com/jabez007/FunctionalCSharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248774981,"owners_count":21159534,"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":["c-sharp","csharp","functional-programming","lambda-calculus","lambda-expressions","lambda-functions","terraformed"],"created_at":"2024-11-10T08:35:49.620Z","updated_at":"2025-04-13T20:11:25.633Z","avatar_url":"https://github.com/jabez007.png","language":"C#","readme":"# Functional C#\nA library of static classes, extension methods, and classes that \napply functional techniques to C#.\n\nI am by no means an expert in this area. This repository is acting \nmore as my personal notes as I study this concept and try applying\nit to my other C# projects.  \n\n## Resources\n* [Functional Programming with C#](https://app.pluralsight.com/library/courses/functional-programming-csharp)\n* [Applying Functional Principles in C#](https://app.pluralsight.com/library/courses/csharp-applying-functional-principles)\n* [Functional Programming in C#](https://www.codeproject.com/Articles/375166/Functional-programming-in-Csharp)\n\n## Other Techniques to Keep in Mind\nWhen using this library to write your own library or application,\nthere are some items you will have to keep in mind in order if you\nwant to stay true to functional C#.\n\n### Singular Behavior Functions\nKeeping the methods/functions to just a singular action (especially \nin class libraries) gives you greater flexibilty in composing \nfunctions to reach the ultimate result of your application. This can\nalso make your library or application much more readable when a \nfunction only does one thing, and the name of that function \ndescribes what it does.\n```\nvar substring = mystring.Substring(3,5);\n```\ngives the same result as \n```\nvar substring = mystring.Skip(3).Take(5);\n```\nbut if you did not already know the behavior of `Substring` the \ncomposition of `Skip` and `Take` more clearly describes what the\nresult ultimately is. The separate `Skip` and `Take` functions\nthen also allows you to compose either or both with other functions\nto obtain more complex behavior.\n\n### Immutable Types\nWhen creating a new class it is up to you to make it immutable to\nenforce the idea that your library or application does not use\nchanging state. To do this you would use readonly getter auto\nproperties and then initialize those properties in the class \nconstructor.\n```\npublic class MyClass\n{\n    public readonly string MyProperty;\n\n    public MyClass(string property)\n    {\n        MyProperty = property;\n    }\n}\n```\nSometimes is does become nessessary to change the property of a \nclass and thus change state that could effect the output of a \nfunction. The compromise for this situation could be to use private\nsetters with a public function that returns the changed object.\n```\npublic class MyClass\n{\n    public string MyProperty { get; private set; }\n\n    public MyClass SetProperty(string property)\n    {\n        MyProperty = property;\n        return this;\n    }\n}\n```\n\n### Monads (the `Result` classes)\n* [Monads in plain English for OO programmers](https://stackoverflow.com/questions/2704652/monad-in-plain-english-for-the-oop-programmer-with-no-fp-background)\n\u003e Formally, a monad is constructed by defining two operations (bind \n\u003e and return) and a type constructor M that must fulfill several \n\u003e properties to allow the correct composition of monadic functions \n\u003e (i.e. functions that use values from the monad as their \n\u003e arguments). The return operation takes a value from a plain type \n\u003e and puts it into a monadic container of type M. The bind operation\n\u003e performs the reverse process, extracting the original value from \n\u003e the container and passing it to the associated next function in \n\u003e the pipeline.\n\n#### Bind\nThe bind method on our `Result\u003cT\u003e` class is what makes the \ncomposition of functions on this amplified type work.\n\n### Exception Handling\n* [Exceptions for flow control](https://enterprisecraftsmanship.com/2015/02/26/exceptions-for-flow-control-in-c/)\n\nUsing exceptions as a sort of flow control for your library or \napplication violates the idea of functional programming that any\nfunction should only return a single type. Using exceptions in flow\ncontrol means that a function could return the type it is supposed\nto return or it could return an exception type. To assist with this,\nthe Result class in this library can be used. Using that Result\nclass, exceptions should be caught and handled at the abosulte \nlowest level possible (as in a library) or at the highest level (as \nin an application). This can be tricky to do sometimes and will\nprobably cause more exceptions to buble up than you are used to\nseeing. This might cause some distress at first, but seeing these \nexceptions will allow you to write in a handle for those exceptions\nand create a more stable library or application in the long run.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabez007%2Ffunctionalcsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjabez007%2Ffunctionalcsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabez007%2Ffunctionalcsharp/lists"}