Skip to content

Instantly share code, notes, and snippets.

View chamook's full-sized avatar
🍫
Would you risk it for a chocolate biscuit?

Adam Guest chamook

🍫
Would you risk it for a chocolate biscuit?
View GitHub Profile
type MiniColour = {
Id : string
Name : string
Hex : string
}
type MiniMyColoursDto = { Colours : MiniColour list }
let toMiniColour (c : Colour) = { MiniColour.Id = c.Id; Name = c.Name; Hex = c.Hex }
let customJsonContentType mimeType data next (ctx : HttpContext) =
sprintf "%s; charset=utf-8" mimeType |> ctx.SetContentType
let serializer = ctx.GetJsonSerializer()
serializer.SerializeToBytes data
|> ctx.WriteBytesAsync
type CustomNegotiationConfig (baseConfig : INegotiationConfig) =
interface INegotiationConfig with
member __.UnacceptableHandler =
baseConfig.UnacceptableHandler
struct Colour: Decodable {
var id: String
var name: String
var hex: String
}
var colours: [Colour] = []
private func loadColours() {
let url = URL(string: "http://localhost:5000/my-colours")
type Colour = {
Id : string
Name : string
Hex : string
RGB : RGB
HSL : HSL
}
and RGB = { Red : int; Green : int; Blue : int }
and HSL = { Hue : int; Saturation : int; Lightness : int }
public class ConfigurationProvider
{
public int TimeoutSeconds =>
Int32.Parse(Environment.GetEnvironmentVariable("TIMEOUT_SECONDS"));
public Uri Endpoint =>
new Uri(Environment.GetEnvironmentVariable("ENDPOINT"));
public int RetryCount =>
Int32.Parse(Environment.GetEnvironmentVariable("RETRY_COUNT"));
}
public interface IConfigurationProvider
{
int TimeoutSeconds { get; }
Uri Endpoint { get; }
int RetryCount { get; }
}
private static Thing MakeThing(string thingName, int thingVal, string thirdParam)
{
if (thingName == null)
throw new ArgumentNullException(nameof(thingName));
if (thirdParam == null)
throw new ArgumentNullException(nameof(thirdParam));
return new Thing(thingName, thingVal, thirdParam);
}
//lurking within other code
var thingFac = new ThingFactory(myThingName, myThingVal);
var thing = thingFac.MakeThing(thirdParam);
public class ThingFactory
{
public string ThingName { get; }
public string ThingValue { get; }
public ThingFactory(string thingName, int thingValue)
{
if (thingName == null)
throw new ArgumentNullException(nameof(thingName));
module AsyncResult =
let map f x =
async {
let! x' = x
return x' |> Result.map f
}
let bind f x =
async {