├── nuget ├── csharprailway.1.0.0.nupkg ├── csharprailway.2.0.0.nupkg └── csharprailway.3.0.0.nupkg ├── .vscode └── launch.json ├── Railway ├── Result.cs ├── Properties │ └── AssemblyInfo.cs ├── RailwayToolkit.csproj ├── Railway.cs └── RailwayExtensions.cs ├── RailwayBuddy ├── Properties │ └── AssemblyInfo.cs ├── RailwayBuddy.csproj └── Program.cs ├── License.txt ├── RailwayBuddy.sln ├── README.md └── .gitignore /nuget/csharprailway.1.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stormy-ua/Railway/HEAD/nuget/csharprailway.1.0.0.nupkg -------------------------------------------------------------------------------- /nuget/csharprailway.2.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stormy-ua/Railway/HEAD/nuget/csharprailway.2.0.0.nupkg -------------------------------------------------------------------------------- /nuget/csharprailway.3.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stormy-ua/Railway/HEAD/nuget/csharprailway.3.0.0.nupkg -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch", 6 | "type": "mono", 7 | "request": "launch", 8 | "program": "${workspaceRoot}/program.exe", 9 | "args": [], 10 | "cwd": "${workspaceRoot}", 11 | "runtimeExecutable": null, 12 | "env": {}, 13 | "externalConsole": false 14 | }, 15 | { 16 | "name": "Attach", 17 | "type": "mono", 18 | "request": "attach", 19 | "address": "localhost", 20 | "port": 5858 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /Railway/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace RailwayToolkit 4 | { 5 | public class Result 6 | { 7 | public static Result Success(T value) 8 | { 9 | return new Result(value, true, null); 10 | } 11 | 12 | public static Result Failure(Exception error) 13 | { 14 | return new Result(default(T), false, error); 15 | } 16 | } 17 | 18 | public class Result 19 | { 20 | readonly T _value; 21 | readonly bool _isSuccess; 22 | readonly Exception _error; 23 | 24 | internal Result(T value, bool isSuccess, Exception error) 25 | { 26 | _value = value; 27 | _isSuccess = isSuccess; 28 | _error = error; 29 | } 30 | 31 | public bool IsSuccess { get { return _isSuccess; } } 32 | 33 | public Exception Error { get { return _error; } } 34 | 35 | public T Value { get { return _value; } } 36 | 37 | public bool IsFailure 38 | { 39 | get { return !IsSuccess; } 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Railway/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle ("Railway")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("")] 12 | [assembly: AssemblyCopyright ("kirill")] 13 | [assembly: AssemblyTrademark ("")] 14 | [assembly: AssemblyCulture ("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion ("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /RailwayBuddy/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | // Information about this assembly is defined by the following attributes. 5 | // Change them to the values specific to your project. 6 | 7 | [assembly: AssemblyTitle ("proto")] 8 | [assembly: AssemblyDescription ("")] 9 | [assembly: AssemblyConfiguration ("")] 10 | [assembly: AssemblyCompany ("")] 11 | [assembly: AssemblyProduct ("")] 12 | [assembly: AssemblyCopyright ("kirill")] 13 | [assembly: AssemblyTrademark ("")] 14 | [assembly: AssemblyCulture ("")] 15 | 16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". 17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision, 18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision. 19 | 20 | [assembly: AssemblyVersion ("1.0.*")] 21 | 22 | // The following attributes are used to specify the signing key for the assembly, 23 | // if desired. See the Mono documentation for more information about signing. 24 | 25 | //[assembly: AssemblyDelaySign(false)] 26 | //[assembly: AssemblyKeyFile("")] 27 | 28 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2016 Kirill Panarin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /RailwayBuddy.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RailwayBuddy", "RailwayBuddy\RailwayBuddy.csproj", "{CA4A1F6C-7F93-4A0D-8511-282973DDA063}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RailwayToolkit", "Railway\RailwayToolkit.csproj", "{FB113E7A-EBA1-4059-8659-137E40610983}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|x86 = Debug|x86 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {CA4A1F6C-7F93-4A0D-8511-282973DDA063}.Debug|x86.ActiveCfg = Debug|x86 17 | {CA4A1F6C-7F93-4A0D-8511-282973DDA063}.Debug|x86.Build.0 = Debug|x86 18 | {CA4A1F6C-7F93-4A0D-8511-282973DDA063}.Release|x86.ActiveCfg = Release|x86 19 | {CA4A1F6C-7F93-4A0D-8511-282973DDA063}.Release|x86.Build.0 = Release|x86 20 | {FB113E7A-EBA1-4059-8659-137E40610983}.Debug|x86.ActiveCfg = Debug|Any CPU 21 | {FB113E7A-EBA1-4059-8659-137E40610983}.Debug|x86.Build.0 = Debug|Any CPU 22 | {FB113E7A-EBA1-4059-8659-137E40610983}.Release|x86.ActiveCfg = Release|Any CPU 23 | {FB113E7A-EBA1-4059-8659-137E40610983}.Release|x86.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(MonoDevelopProperties) = preSolution 29 | StartupItem = proto\proto.csproj 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Railway/RailwayToolkit.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | {FB113E7A-EBA1-4059-8659-137E40610983} 7 | Library 8 | RailwayToolkit 9 | RailwayToolkit 10 | 11 | 12 | true 13 | full 14 | false 15 | bin\Debug 16 | DEBUG; 17 | prompt 18 | 4 19 | false 20 | 21 | 22 | full 23 | true 24 | bin\Release 25 | prompt 26 | 4 27 | false 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /RailwayBuddy/RailwayBuddy.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | {CA4A1F6C-7F93-4A0D-8511-282973DDA063} 7 | Exe 8 | proto 9 | proto 10 | 11 | 12 | true 13 | full 14 | false 15 | bin\Debug 16 | DEBUG; 17 | prompt 18 | 4 19 | true 20 | x86 21 | 22 | 23 | full 24 | true 25 | bin\Release 26 | prompt 27 | 4 28 | true 29 | x86 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | {fb113e7a-eba1-4059-8659-137e40610983} 41 | RailwayToolkit 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /Railway/Railway.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace RailwayToolkit 5 | { 6 | public static class Railway 7 | { 8 | public static Func> Apply(Func> f) 9 | { 10 | return f.TryCatch(); 11 | } 12 | 13 | public static Func> Apply(Func> f) 14 | { 15 | return f.TryCatch(); 16 | } 17 | 18 | public static Func> Apply(Action f) 19 | { 20 | return f.Tee().Switch().TryCatch(); 21 | } 22 | 23 | public static Func> Apply(Func f) 24 | { 25 | return f.Switch().TryCatch(); 26 | } 27 | 28 | public static Func> Apply(Func f) 29 | { 30 | return f.Switch().TryCatch(); 31 | } 32 | 33 | public static Func> OnSuccess(this Func> f, Func> onSuccess) 34 | { 35 | return f.Compose(onSuccess.TryCatch().Bind()); 36 | } 37 | 38 | public static Func> OnSuccess(this Func> f, Func onSuccess) 39 | { 40 | return f.Compose(onSuccess.Switch().TryCatch().Bind()); 41 | } 42 | 43 | public static Func> OnSuccess(this Func> f, Action onSuccess) 44 | { 45 | return f.Compose(onSuccess.Tee().Switch().TryCatch().Bind()); 46 | } 47 | 48 | public static Func> OnSuccess(this Func> f, 49 | Func aggregateSuccess, Func aggregateFailure, 50 | params Func>[] onSuccesses) 51 | { 52 | return f.Compose(onSuccesses.Aggregate((f1, f2) => f1.Plus(f2, aggregateSuccess, aggregateFailure)).Bind()); 53 | } 54 | 55 | public static Func> OnFailure(this Func> f, Func onFailure) 56 | { 57 | return f.Compose(Unit().DoubleMap(onFailure)); 58 | } 59 | 60 | public static Func> OnFailure(this Func> f, Action onFailure) 61 | { 62 | return f.Compose(Unit().DoubleMap(onFailure.Tee())); 63 | } 64 | 65 | private static Func Unit() 66 | { 67 | return t => t; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /RailwayBuddy/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using RailwayToolkit; 3 | 4 | namespace RailwayBuddy 5 | { 6 | public class Request 7 | { 8 | public string Name { get; set; } 9 | public string Email { get; set; } 10 | 11 | public override string ToString () 12 | { 13 | return string.Format ("[Request: Name={0}, Email={1}]", Name, Email); 14 | } 15 | } 16 | 17 | class MainClass 18 | { 19 | private static Result ValidateName(Request request) 20 | { 21 | if (string.IsNullOrWhiteSpace (request.Name)) 22 | { 23 | return Result.Failure(new Exception("Name must not be blank")); 24 | } 25 | 26 | return Result.Success (request); 27 | } 28 | 29 | private static Result ValidateEmail(Request request) 30 | { 31 | if (string.IsNullOrWhiteSpace (request.Email)) 32 | { 33 | return Result.Failure(new Exception("Email must not be blank")); 34 | } 35 | 36 | return Result.Success (request); 37 | } 38 | 39 | private static void LogRequest(Request request) 40 | { 41 | Console.WriteLine("Name: {0}, Email: {1}", request.Name, request.Email); 42 | } 43 | 44 | public static void Main (string[] args) 45 | { 46 | // combine validation functions 47 | var combinedValidation = Railway 48 | // log inpiut request 49 | .Apply (r => LogRequest(r)) 50 | // do email and name validation in parallel and combine errors 51 | .OnSuccess( 52 | (r1, r2) => r1, 53 | (e1, e2) => new AggregateException(e1, e2), 54 | r => ValidateName(r), 55 | r => ValidateEmail(r) 56 | ) 57 | // extract request name 58 | .OnSuccess (request => request.Name) 59 | // log extracted name 60 | .OnSuccess (name => Console.WriteLine ("Name: {0}", name)) 61 | // append dash to name 62 | .OnSuccess (name => name + "-") 63 | // log name 64 | .OnSuccess (name => Console.WriteLine ("Name: {0}", name)) 65 | // make nume uppercase 66 | .OnSuccess (name => name.ToUpper ()) 67 | // log name 68 | .OnSuccess (name => Console.WriteLine ("Name: {0}", name)) 69 | // log failure if any occured during the pipeline execution 70 | .OnFailure (e => Console.WriteLine ("Failure: {0} ", e.Message)); 71 | 72 | // invoke combined function 73 | var result = combinedValidation (new Request { Name = "", Email = "" }); 74 | //var result = combinedValidation (new Request { Name = "", Email = "a@b.c" }); 75 | //var result = combinedValidation (new Request { Name = "Kirill", Email = "" }); 76 | //var result = combinedValidation (new Request { Name = "Kirill", Email = "a@b.c" }); 77 | 78 | // process result 79 | switch (result.IsSuccess) { 80 | case true: 81 | Console.WriteLine ("Success. {0}", result.Value); 82 | break; 83 | case false: 84 | Console.WriteLine ("Failure: {0}", result.Error); 85 | break; 86 | } 87 | 88 | Console.ReadLine (); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Railway/RailwayExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace RailwayToolkit 5 | { 6 | /// 7 | /// Group of functions that are designed to work with a type (here represented by railway track), 8 | /// with the design goal that bigger pieces can be built by adapting and combining smaller pieces. 9 | /// 10 | public static class RailwayExtensions 11 | { 12 | /// 13 | /// Normal composition. A combiner that takes two normal functions and creates a new function 14 | /// by connecting them in series. 15 | /// 16 | public static Func Compose(this Func g, Func f) 17 | { 18 | return x => f(g(x)); 19 | } 20 | 21 | /// 22 | /// An adapter that takes a switch function and creates a new function that accepts 23 | /// two-track values as input. 24 | /// 25 | public static Func, Result> Bind(this Func> f) 26 | { 27 | return x => 28 | { 29 | if (x.IsFailure) { 30 | return Result.Failure(x.Error); 31 | } 32 | 33 | return f (x.Value); 34 | }; 35 | } 36 | 37 | /// 38 | /// An adapter that takes a normal one-track function and turns it into a switch function, 39 | /// but also catches exceptions. 40 | /// 41 | public static Func> TryCatch(this Func> f) 42 | { 43 | return x => 44 | { 45 | try 46 | { 47 | return f (x); 48 | } 49 | catch(Exception exc){ 50 | return Result.Failure(exc); 51 | } 52 | }; 53 | } 54 | 55 | /// 56 | /// An adapter that takes a normal one-track function and turns it into a switch function. 57 | /// (Also known as a "lift" in some contexts.) 58 | /// 59 | public static Func> Switch(this Func f) 60 | { 61 | return x => Result.Success(f(x)); 62 | } 63 | 64 | /// 65 | /// An adapter that takes a dead-end function and turns it into a one-track function 66 | /// that can be used in a data flow. (Also known as tap.) 67 | /// 68 | public static Func Tee(this Action f) 69 | { 70 | return x => { 71 | f (x); 72 | 73 | return x; 74 | }; 75 | } 76 | 77 | /// 78 | /// An adapter that takes two one-track functions and turns them into a single two-track function. 79 | /// (Also known as bimap.) 80 | /// 81 | public static Func, Result> DoubleMap(this Func success, Func failure) 82 | { 83 | return x => { 84 | if (x.IsFailure) { 85 | return Result.Failure(failure(x.Error)); 86 | } 87 | 88 | return Result.Success(success(x.Value)); 89 | }; 90 | } 91 | 92 | /// 93 | /// An adapter that takes a normal one-track function and turns it into a two-track function. 94 | /// (Also known as a "lift" in some contexts.) 95 | /// 96 | public static Func, Result> Map(this Func f) 97 | { 98 | return x => { 99 | if (x.IsFailure) { 100 | return Result.Failure(x.Error); 101 | } 102 | 103 | return Result.Success(f(x.Value)); 104 | }; 105 | } 106 | 107 | /// 108 | /// A combiner that takes two switch functions and creates a new switch function 109 | /// by joining them in "parallel" and "adding" the results. 110 | /// (Also known as ++ and <+> in other contexts.) 111 | /// 112 | public static Func> Plus( 113 | this Func> switch1, 114 | Func> switch2, 115 | Func aggregateSuccess, Func aggregateFailure) 116 | 117 | { 118 | return x => { 119 | var result1 = switch1(x); 120 | var result2 = switch2(x); 121 | 122 | if(result1.IsSuccess && result2.IsSuccess) { 123 | return Result.Success(aggregateSuccess(result1.Value, result2.Value)); 124 | } 125 | 126 | if(result1.IsSuccess && result2.IsFailure){ 127 | return Result.Failure(result2.Error); 128 | } 129 | 130 | if(result1.IsFailure && result2.IsSuccess) { 131 | return Result.Failure(result1.Error); 132 | } 133 | 134 | return Result.Failure(aggregateFailure(result1.Error, result2.Error)); 135 | }; 136 | } 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Set of railway-oriented C# extension methods which could be used as building blocks for data-flow style application. 2 | 3 | Inspired by [Railway oriented programming](http://fsharpforfunandprofit.com/posts/recipe-part2/) 4 | 5 | # Nuget 6 | 7 | [![Nuget](https://img.shields.io/nuget/v/CSharpRailway.svg)](https://www.nuget.org/packages/CSharpRailway/) 8 | [![Nuget](https://img.shields.io/nuget/dt/CSharpRailway.svg)](https://www.nuget.org/packages/CSharpRailway/) 9 | 10 | # Supported railway-oriented functions 11 | 12 | **Function** | **Description** 13 | --- | --- 14 | ```Compose``` | Normal composition. A combiner that takes two normal functions and creates a new function by connecting them in series. 15 | ```Bind``` | An adapter that takes a switch function and creates a new function that accepts two-track values as input. 16 | ```TryCatch``` | An adapter that takes a normal one-track function and turns it into a switch function, but also catches exceptions. 17 | ```Switch``` | An adapter that takes a normal one-track function and turns it into a switch function. (Also known as a "lift" in some contexts.) 18 | ```Tee``` | An adapter that takes a dead-end function and turns it into a one-track function that can be used in a data flow. (Also known as tap.) 19 | ```Map``` | An adapter that takes a normal one-track function and turns it into a two-track function. (Also known as a "lift" in some contexts.) 20 | ```DoubleMap``` | An adapter that takes two one-track functions and turns them into a single two-track function. (Also known as bimap.) 21 | ```Plus``` | A combiner that takes two switch functions and creates a new switch function by joining them in "parallel" and "adding" the results. (Also known as ++ and <+> in other contexts.) 22 | 23 | # Usage Example 24 | 25 | ```csharp 26 | public class Request 27 | { 28 | public string Name { get; set; } 29 | public string Email { get; set; } 30 | 31 | public override string ToString () 32 | { 33 | return string.Format ("[Request: Name={0}, Email={1}]", Name, Email); 34 | } 35 | } 36 | 37 | class MainClass 38 | { 39 | private static Result ValidateName(Request request) 40 | { 41 | if (string.IsNullOrWhiteSpace (request.Name)) 42 | { 43 | return Result.Failure(new Exception("Name must not be blank")); 44 | } 45 | 46 | return Result.Success (request); 47 | } 48 | 49 | private static Result ValidateEmail(Request request) 50 | { 51 | if (string.IsNullOrWhiteSpace (request.Email)) 52 | { 53 | return Result.Failure(new Exception("Email must not be blank")); 54 | } 55 | 56 | return Result.Success (request); 57 | } 58 | 59 | private static void LogRequest(Request request) 60 | { 61 | Console.WriteLine("Name: {0}, Email: {1}", request.Name, request.Email); 62 | } 63 | 64 | public static void Main (string[] args) 65 | { 66 | // combine validation functions 67 | var combinedValidation = Railway 68 | // log inpiut request 69 | .Apply (r => LogRequest(r)) 70 | // do email and name validation in parallel and combine errors 71 | .OnSuccess( 72 | (r1, r2) => r1, 73 | (e1, e2) => new AggregateException(e1, e2), 74 | r => ValidateName(r), 75 | r => ValidateEmail(r) 76 | ) 77 | // extract request name 78 | .OnSuccess (request => request.Name) 79 | // log extracted name 80 | .OnSuccess (name => Console.WriteLine ("Name: {0}", name)) 81 | // append dash to name 82 | .OnSuccess (name => name + "-") 83 | // log name 84 | .OnSuccess (name => Console.WriteLine ("Name: {0}", name)) 85 | // make nume uppercase 86 | .OnSuccess (name => name.ToUpper ()) 87 | // log name 88 | .OnSuccess (name => Console.WriteLine ("Name: {0}", name)) 89 | // log failure if any occured during the pipeline execution 90 | .OnFailure (e => Console.WriteLine ("Failure: {0} ", e.Message)); 91 | 92 | // invoke combined function 93 | var result = combinedValidation (new Request { Name = "", Email = "" }); 94 | //var result = combinedValidation (new Request { Name = "", Email = "a@b.c" }); 95 | //var result = combinedValidation (new Request { Name = "Kirill", Email = "" }); 96 | //var result = combinedValidation (new Request { Name = "Kirill", Email = "a@b.c" }); 97 | 98 | // process result 99 | switch (result.IsSuccess) { 100 | case true: 101 | Console.WriteLine ("Success. {0}", result.Value); 102 | break; 103 | case false: 104 | Console.WriteLine ("Failure: {0}", result.Error); 105 | break; 106 | } 107 | 108 | Console.ReadLine (); 109 | } 110 | } 111 | ``` 112 | 113 | [Full example source code](https://github.com/stormy-ua/Functional/blob/master/RailwayBuddy/Program.cs) 114 | 115 | 116 | ## License 117 | 118 | Licensed under the [MIT License](https://github.com/stormy-ua/Railway/blob/master/License.txt). 119 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | # Uncomment if you have tasks that create the project's static files in wwwroot 27 | #wwwroot/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # DNX 43 | project.lock.json 44 | artifacts/ 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opendb 79 | *.opensdf 80 | *.sdf 81 | *.cachefile 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | *.vspx 87 | *.sap 88 | 89 | # TFS 2012 Local Workspace 90 | $tf/ 91 | 92 | # Guidance Automation Toolkit 93 | *.gpState 94 | 95 | # ReSharper is a .NET coding add-in 96 | _ReSharper*/ 97 | *.[Rr]e[Ss]harper 98 | *.DotSettings.user 99 | 100 | # JustCode is a .NET coding add-in 101 | .JustCode 102 | 103 | # TeamCity is a build add-in 104 | _TeamCity* 105 | 106 | # DotCover is a Code Coverage Tool 107 | *.dotCover 108 | 109 | # NCrunch 110 | _NCrunch_* 111 | .*crunch*.local.xml 112 | nCrunchTemp_* 113 | 114 | # MightyMoose 115 | *.mm.* 116 | AutoTest.Net/ 117 | 118 | # Web workbench (sass) 119 | .sass-cache/ 120 | 121 | # Installshield output folder 122 | [Ee]xpress/ 123 | 124 | # DocProject is a documentation generator add-in 125 | DocProject/buildhelp/ 126 | DocProject/Help/*.HxT 127 | DocProject/Help/*.HxC 128 | DocProject/Help/*.hhc 129 | DocProject/Help/*.hhk 130 | DocProject/Help/*.hhp 131 | DocProject/Help/Html2 132 | DocProject/Help/html 133 | 134 | # Click-Once directory 135 | publish/ 136 | 137 | # Publish Web Output 138 | *.[Pp]ublish.xml 139 | *.azurePubxml 140 | # TODO: Comment the next line if you want to checkin your web deploy settings 141 | # but database connection strings (with potential passwords) will be unencrypted 142 | *.pubxml 143 | *.publishproj 144 | 145 | # NuGet Packages 146 | #*.nupkg 147 | # The packages folder can be ignored because of Package Restore 148 | **/packages/* 149 | # except build/, which is used as an MSBuild target. 150 | !**/packages/build/ 151 | # Uncomment if necessary however generally it will be regenerated when needed 152 | #!**/packages/repositories.config 153 | # NuGet v3's project.json files produces more ignoreable files 154 | *.nuget.props 155 | *.nuget.targets 156 | 157 | # Microsoft Azure Build Output 158 | csx/ 159 | *.build.csdef 160 | 161 | # Microsoft Azure Emulator 162 | ecf/ 163 | rcf/ 164 | 165 | # Microsoft Azure ApplicationInsights config file 166 | ApplicationInsights.config 167 | 168 | # Windows Store app package directory 169 | AppPackages/ 170 | BundleArtifacts/ 171 | 172 | # Visual Studio cache files 173 | # files ending in .cache can be ignored 174 | *.[Cc]ache 175 | # but keep track of directories ending in .cache 176 | !*.[Cc]ache/ 177 | 178 | # Others 179 | ClientBin/ 180 | ~$* 181 | *~ 182 | *.dbmdl 183 | *.dbproj.schemaview 184 | *.pfx 185 | *.publishsettings 186 | node_modules/ 187 | orleans.codegen.cs 188 | 189 | # RIA/Silverlight projects 190 | Generated_Code/ 191 | 192 | # Backup & report files from converting an old project file 193 | # to a newer Visual Studio version. Backup files are not needed, 194 | # because we have git ;-) 195 | _UpgradeReport_Files/ 196 | Backup*/ 197 | UpgradeLog*.XML 198 | UpgradeLog*.htm 199 | 200 | # SQL Server files 201 | *.mdf 202 | *.ldf 203 | 204 | # Business Intelligence projects 205 | *.rdl.data 206 | *.bim.layout 207 | *.bim_*.settings 208 | 209 | # Microsoft Fakes 210 | FakesAssemblies/ 211 | 212 | # GhostDoc plugin setting file 213 | *.GhostDoc.xml 214 | 215 | # Node.js Tools for Visual Studio 216 | .ntvs_analysis.dat 217 | 218 | # Visual Studio 6 build log 219 | *.plg 220 | 221 | # Visual Studio 6 workspace options file 222 | *.opt 223 | 224 | # Visual Studio LightSwitch build output 225 | **/*.HTMLClient/GeneratedArtifacts 226 | **/*.DesktopClient/GeneratedArtifacts 227 | **/*.DesktopClient/ModelManifest.xml 228 | **/*.Server/GeneratedArtifacts 229 | **/*.Server/ModelManifest.xml 230 | _Pvt_Extensions 231 | 232 | # Paket dependency manager 233 | .paket/paket.exe 234 | 235 | # FAKE - F# Make 236 | .fake/ 237 | --------------------------------------------------------------------------------