---
title: Order example
---
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE-ITEM : contains
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
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.Diagnostics; | |
using System.Net; | |
using System.Net.Sockets; | |
using static System.Text.Encoding; | |
using static System.Console; | |
const int MaxUdpByteSize = 65527; | |
static Socket CreateSocket(int port) | |
{ |
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
module Result = | |
let join x1 x2 = | |
match x1, x2 with | |
| Ok x1res, Ok x2res -> Ok(x1res, x2res) | |
| Error e1, Error e2 -> Error(e1 @ e2) | |
| Error e, _ | |
| _, Error e -> Error e | |
type ResultBuilder() = |
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 UrlServiceResolverHandler : DelegatingHandler | |
{ | |
readonly ILogger<UrlServiceResolverHandler> logger; | |
public UrlServiceResolverHandler(ILogger<UrlServiceResolverHandler> logger) | |
{ | |
this.logger = logger; | |
InnerHandler = new HttpClientHandler(); | |
} |
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.IO.Compression; | |
using System.Text; | |
interface ICompressor | |
{ | |
public const string Header = "[z]"; | |
Task<string> Compress(string text); | |
Task<string> Decompress(string text); | |
} |
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.Globalization; | |
using System.Text.Json; | |
using System.Text.Json.Serialization; | |
namespace Heptapod.Models.Values; | |
[JsonConverter(typeof(UtcJsonConverter))] | |
public readonly struct DateUtc | |
{ | |
public DateUtc(DateTime dateTime) => DateTime = dateTime.ToUniversalTime(); |
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
open System | |
//Helpers | |
let printOpt opt = | |
match opt with | |
|None -> printfn "None" | |
|Some v -> printfn "Some %s" v | |
// safe functions | |
let exclaimIt str = if str = "" then None else Some (str + "!") |
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 abstract record Result<TOk, TError> | |
{ | |
public sealed record Ok(TOk Value) : Result<TOk, TError> | |
{ | |
public override TOk Default(TOk defaultValueIfError) => Value; | |
public override T Match<T>(Func<TOk, T> ok, Func<TError, T> error) => ok(Value); | |
public override Result<TMap, TError> Select<TMap>(Func<TOk, TMap> map) => map(Value); | |
public override Result<TMap, TError> Bind<TMap>(Func<TOk, Result<TMap, TError>> bind) => bind(Value); | |
public override bool IsError => 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
using System.ComponentModel; | |
public static string GetDescription<T>(this T option) where T : Enum => option | |
.GetType().GetMember(option.ToString()) | |
.SelectMany(p => p.GetCustomAttributes(typeof(DescriptionAttribute), true)) | |
.FirstOrDefault() is DescriptionAttribute attr | |
? attr.Description | |
: option.ToString(); |
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; | |
#region 'Implementaçao exemplo do result' | |
public static class Result { | |
public static Result<TSuccess,TFailure> Ok<TSuccess, TFailure>(TSuccess value) => new OkResult<TSuccess, TFailure>(value); | |
public static Result<TSuccess,TFailure> Error<TSuccess, TFailure>(TFailure value) => new ErrorResult<TSuccess, TFailure>(value); | |
} | |
public abstract class Result<TOk, TError> { | |