Skip to content

Latest commit

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

RailSharp

RailSharp

A small railway oriented library that offers a simple implementation of the Option type and Result type in C#.

Azure DevOps releasesAzure DevOps buildsAzure DevOps testsAzure DevOps coverageNugetNuget downloadsLicense

Quick links:Docs,API

What is RailSharp?

RailSharp uses railway oriented programming to help handle errors and to deal with our old friend NullReferenceException.

To learn more about railway oriented programming, take a look here!

How do I get started?

Here's a quick overview of how to use the Option and Result types:

Option type:

// First, instantiates an option using `Option.None`, `Option.Some(T)` // or one of the extension methods.varoption=Option.Some(newUser("Alan Turing"));varuserName=option// Then, handle the happy path (i.e. when the option contains a value)..Map(user =>user.Name).Do(name =>SayHi(name))// Finally, handle the sad path (i.e. when the option contains no value)..Reduce(()=>"Anonymous")

Result type:

// First, instantiates a result using `Result.Failure(TFailure)`,// `Result.Success(TSuccess)` or one of the extension methods.varresult=Result.Failure(newUserNotFound());varhttpResponse=result// Then, handle the happy path (i.e. when the result is a success)..Map(data =>Ok(data))// Finally, handle the sad paths (i.e. when the result is a failure)..Catch<UserNotFound>(err =>NotFound()).Catch(err =>InternalServerError())

You can also take a look at the API documentation or even the unit tests for a deeper understanding.

How do I install it?

First, install NuGet. Then, install the NuGet package avalaible at nuget.org using the dotnet CLI:

dotnet add package RailSharp

I have an issue...

First, you can check if your issue has already been tracked here.

Otherwise, you can check if it's already fixed by pulling the develop branch, building the solution and then using the generated DLL files direcly in your project.

If you still hit a problem, please document it and post it here.

Credits

The original code has been inspired from the Pluralsight course Making Your C# Code More Functional by Zoran Horvat.

License

RailSharp is Copyright © 2018 SoftFrame under the MIT license.

Releases

Packages

Used by

Contributors

Languages