This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace System.Threading.Tasks | |
{ | |
public class Workspace | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Functional | |
{ | |
public static class FunctionalExtensions | |
{ | |
public static Func<TA, TA> Id<TA>() => x => x; | |
public static Func<TA, TB> Const<TA, TB>(this TB x) => _ => x; | |
public static Func<TA, TB> ToFunc<TA, TB>(Func<TA, TB> f) => f; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Monads | |
{ | |
public class Maybe<TA> | |
{ | |
private readonly TA _value; | |
private bool IsPresent => _value != null; | |
private Maybe() { _value = default(TA); } | |
private Maybe(TA value) { _value = value; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace System.IO | |
{ | |
public sealed class VirtualStream : Stream, ICloneable | |
{ | |
/// <summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.IO | |
open System | |
open System.IO | |
type MemoryFlag = | |
| AutoOverflowToDisk | |
| OnlyInMemory | |
| OnlyToDisk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Outcome<JObject, string[]> Load(Stream content) | |
{ | |
if (content is null) | |
{ | |
throw new ArgumentNullException(nameof(content)); | |
} | |
var settings = new JsonLoadSettings | |
{ | |
CommentHandling = CommentHandling.Ignore, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BookJson | |
{ | |
[JsonConstructor] | |
public BookJson(string author, string isbn13, int pages) | |
{ | |
Author = Sanitize.RegexReplace(pattern: "( ){2,}", replacement: String.Empty, input: author).WhiteMatch(@"[a-zA-Z\. ]+"); | |
ISBN13 = Sanitize.RemoveWhitespace(isbn13).BlackList(@"\-"); | |
Pages = pages; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var schema = JSchema.Parse( | |
@"{ 'description': 'A book', | |
'type': 'object', | |
'properties': | |
{ 'author': { 'type': 'string', 'minLength': 1, 'maxLength': 100 }, | |
'isbn13': { 'type': 'string', 'minLength': 13, 'maxLength': 17 }, | |
'pages': { 'type': 'number', 'minimum': 1, 'maximum': 1000 } } }"); | |
schema.AllowAdditionalProperties = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Author | |
{ | |
private readonly string _name; | |
private Author(string name) { _name = name; } | |
public static ValidationResult<Author> Create(string author) | |
{ | |
const string name = @"[A-Z]{1}[a-z]*\.?"; | |
string pattern = $@"^({name})( {name})*$"; | |
return Spec.Of<string>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Author = | |
private Author of string with | |
static member create x = | |
let name = @"[A-Z]{1}[a-z]*\.?" | |
let pattern = sprintf "^(%s)( %s)*$" name name | |
specModel Author x { | |
notNullOrWhiteSpace "author name should not be blank" | |
greaterThanOrEqualOf String.length 1 "author name should at least be a single character" | |
matches pattern "author name should only contain names starting with a capital" } |
OlderNewer