├── .gitignore └── Src ├── After ├── FunctionalCSharp.sln └── FunctionalCSharp │ ├── App.config │ ├── Disposable.cs │ ├── FunctionalCSharp.csproj │ ├── FunctionalExtensions.cs │ ├── HtmlBuilder.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Result.cs │ ├── StreamFactory.cs │ ├── StringBuilderExtensions.cs │ └── Validator.cs └── Before ├── FunctionalCSharp.sln └── FunctionalCSharp ├── App.config ├── FunctionalCSharp.csproj ├── Program.cs ├── Properties └── AssemblyInfo.cs └── StreamFactory.cs /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Visual Studio 3 | ################# 4 | 5 | ## Ignore Visual Studio temporary files, build results, and 6 | ## files generated by popular Visual Studio add-ons. 7 | 8 | # User-specific files 9 | *.suo 10 | *.user 11 | *.sln.docstates 12 | 13 | # Build results 14 | 15 | [Dd]ebug/ 16 | [Rr]elease/ 17 | x64/ 18 | build/ 19 | [Bb]in/ 20 | [Oo]bj/ 21 | 22 | # MSTest test Results 23 | [Tt]est[Rr]esult*/ 24 | [Bb]uild[Ll]og.* 25 | 26 | *_i.c 27 | *_p.c 28 | *.ilk 29 | *.meta 30 | *.obj 31 | *.pch 32 | *.pdb 33 | *.pgc 34 | *.pgd 35 | *.rsp 36 | *.sbr 37 | *.tlb 38 | *.tli 39 | *.tlh 40 | *.tmp 41 | *.tmp_proj 42 | *.log 43 | *.vspscc 44 | *.vssscc 45 | .builds 46 | *.pidb 47 | *.log 48 | *.scc 49 | 50 | # Visual C++ cache files 51 | ipch/ 52 | *.aps 53 | *.ncb 54 | *.opensdf 55 | *.sdf 56 | *.cachefile 57 | 58 | # Visual Studio profiler 59 | *.psess 60 | *.vsp 61 | *.vspx 62 | 63 | # Guidance Automation Toolkit 64 | *.gpState 65 | 66 | # ReSharper is a .NET coding add-in 67 | _ReSharper*/ 68 | *.[Rr]e[Ss]harper 69 | 70 | # TeamCity is a build add-in 71 | _TeamCity* 72 | 73 | # DotCover is a Code Coverage Tool 74 | *.dotCover 75 | 76 | # NCrunch 77 | *.ncrunch* 78 | .*crunch*.local.xml 79 | 80 | # Installshield output folder 81 | [Ee]xpress/ 82 | 83 | # DocProject is a documentation generator add-in 84 | DocProject/buildhelp/ 85 | DocProject/Help/*.HxT 86 | DocProject/Help/*.HxC 87 | DocProject/Help/*.hhc 88 | DocProject/Help/*.hhk 89 | DocProject/Help/*.hhp 90 | DocProject/Help/Html2 91 | DocProject/Help/html 92 | 93 | # Click-Once directory 94 | publish/ 95 | 96 | # Publish Web Output 97 | *.Publish.xml 98 | *.pubxml 99 | 100 | # NuGet Packages Directory 101 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 102 | #packages/ 103 | 104 | # Windows Azure Build Output 105 | csx 106 | *.build.csdef 107 | 108 | # Windows Store app package directory 109 | AppPackages/ 110 | 111 | # Others 112 | sql/ 113 | *.Cache 114 | ClientBin/ 115 | [Ss]tyle[Cc]op.* 116 | ~$* 117 | *~ 118 | *.dbmdl 119 | *.[Pp]ublish.xml 120 | *.pfx 121 | *.publishsettings 122 | 123 | # RIA/Silverlight projects 124 | Generated_Code/ 125 | 126 | # Backup & report files from converting an old project file to a newer 127 | # Visual Studio version. Backup files are not needed, because we have git ;-) 128 | _UpgradeReport_Files/ 129 | Backup*/ 130 | UpgradeLog*.XML 131 | UpgradeLog*.htm 132 | 133 | # SQL Server files 134 | App_Data/*.mdf 135 | App_Data/*.ldf -------------------------------------------------------------------------------- /Src/After/FunctionalCSharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FunctionalCSharp", "FunctionalCSharp\FunctionalCSharp.csproj", "{DC0FE2A9-3967-4247-B8C3-D597C497F928}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DC0FE2A9-3967-4247-B8C3-D597C497F928}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DC0FE2A9-3967-4247-B8C3-D597C497F928}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DC0FE2A9-3967-4247-B8C3-D597C497F928}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DC0FE2A9-3967-4247-B8C3-D597C497F928}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Src/After/FunctionalCSharp/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Src/After/FunctionalCSharp/Disposable.cs: -------------------------------------------------------------------------------- 1 | namespace System 2 | { 3 | public static class Disposable 4 | { 5 | public static TResult Using 6 | ( 7 | Func factory, 8 | Func fn) 9 | where TDisposable : IDisposable 10 | { 11 | using (var disposable = factory()) 12 | { 13 | return fn(disposable); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Src/After/FunctionalCSharp/FunctionalCSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {DC0FE2A9-3967-4247-B8C3-D597C497F928} 8 | Exe 9 | Properties 10 | FunctionalCSharp 11 | FunctionalCSharp 12 | v4.6 13 | 512 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 66 | -------------------------------------------------------------------------------- /Src/After/FunctionalCSharp/FunctionalExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace System 2 | { 3 | public static class FunctionalExtensions 4 | { 5 | public static T Tee(this T @this, Action action) 6 | { 7 | action(@this); 8 | return @this; 9 | } 10 | 11 | public static TResult Map( 12 | this TSource @this, 13 | Func fn) => 14 | fn(@this); 15 | 16 | public static T When( 17 | this T @this, 18 | Func predicate, 19 | Func fn) => 20 | predicate() 21 | ? fn(@this) 22 | : @this; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Src/After/FunctionalCSharp/HtmlBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace FunctionalCSharp 6 | { 7 | public static class HtmlBuilder 8 | { 9 | public static Func, string> BuildSelectBox(string id, bool includeUnknown) => 10 | options => 11 | new StringBuilder() 12 | .AppendFormattedLine("", id); 14 | html.AppendLine(); 15 | 16 | if (includeUnknown) 17 | { 18 | html.AppendLine("\t"); 19 | } 20 | 21 | foreach (var opt in options) 22 | { 23 | html.AppendFormat("\t", opt.Key, opt.Value); 24 | html.AppendLine(); 25 | } 26 | 27 | html.AppendLine(""); 28 | 29 | return html.ToString(); 30 | } 31 | 32 | static void Main(string[] args) 33 | { 34 | byte[] buffer; 35 | 36 | using (var stream = StreamFactory.GetStream()) 37 | { 38 | buffer = new byte[stream.Length]; 39 | stream.Read(buffer, 0, (int)stream.Length); 40 | } 41 | 42 | var options = 43 | Encoding 44 | .UTF8 45 | .GetString(buffer) 46 | .Split(new[] { Environment.NewLine, }, StringSplitOptions.RemoveEmptyEntries) 47 | .Select((s, ix) => Tuple.Create(ix, s)) 48 | .ToDictionary(k => k.Item1, v => v.Item2); 49 | 50 | var selectBox = BuildSelectBox(options, "theDoctors", true); 51 | 52 | Console.WriteLine(selectBox); 53 | 54 | Console.ReadLine(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Src/Before/FunctionalCSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FixingOO")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FixingOO")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("95c39cb2-24bc-47b7-9e80-92134230a038")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Src/Before/FunctionalCSharp/StreamFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace FunctionalCSharp 9 | { 10 | public static class StreamFactory 11 | { 12 | public static Stream GetStream() 13 | { 14 | var doctors = 15 | String.Join( 16 | Environment.NewLine, 17 | new[] { 18 | "Hartnell", "Troughton", "Pertwee", "T. Baker", 19 | "Davison", "C. Baker", "McCoy", "McGann", "Hurt", 20 | "Eccleston", "Tennant", "Smith", "Capaldi" }); 21 | 22 | var buffer = Encoding.UTF8.GetBytes(doctors); 23 | 24 | var stream = new MemoryStream(); 25 | stream.Write(buffer, 0, buffer.Length); 26 | stream.Position = 0L; 27 | 28 | return stream; 29 | } 30 | } 31 | } 32 | --------------------------------------------------------------------------------