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
typealias Completion = () -> Void
class DataFetcher {
private var colours: [Colour]
private var items: Dictionary<String, [Item]>
private var prices: [Price]
public var coloursAndItems: [ColourWithItems] {
var result: [ColourWithItems] = []
version: "3"
services:
colours:
build: ./colours/src/Chamook.Colours
ports:
- 8081:80
items:
build: ./items/src/Chamook.Items
ports:
type Price = { ItemId: string; Price: Decimal }
let getPriceForItem itemId : HttpHandler =
match itemId with
| "1" -> { ItemId = "1"; Price = 2.00M } |> Successful.OK
| "2" -> { ItemId = "2"; Price = 4.50M } |> Successful.OK
| _ -> RequestErrors.NOT_FOUND ()
let webApp =
choose [
struct RGB: Decodable {
var red: Int
var green: Int
var blue: Int
}
struct Colour: Decodable {
var id: String
var name: String
var hex: String
version: "3"
services:
colours:
build: ./colours/src/Chamook.Colours
ports:
- 8081:80
items:
build: ./items/src/Chamook.Items
ports:
public class Item
{
public string Name { get; }
public string Id { get; }
public string ColourId { get; }
public Item(string name, string id, string colourId)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Id = id ?? throw new ArgumentNullException(nameof(id));
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 }
struct RGB: Decodable {
var red: Int
var green: Int
var blue: Int
enum CodingKeys: String, CodingKey {
case red = "Red"
case green = "Green"
case blue = "Blue"
}
let tryGetPropertyName<'a> propertyName =
FSharpType.GetRecordFields typeof<'a>
|> Array.tryFind
(fun x -> String.Equals(x.Name, propertyName, StringComparison.OrdinalIgnoreCase))
|> Option.map (fun x -> x.Name)
let includingRegex = Regex("including=(.*?)(\Z|\0)")
let (|FilteredRepresentation|_|) (accept : string option) =
match accept with
let url = URL(string: "http://localhost:5000/my-colours")!
var request = URLRequest(url: url)
request.setValue("application/vnd.chamook.mini-colours+json", forHTTPHeaderField: "Accept")
URLSession.shared.dataTask(with: request) { [weak self] (data, response, error) in
...