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
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] = [] |
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
version: "3" | |
services: | |
colours: | |
build: ./colours/src/Chamook.Colours | |
ports: | |
- 8081:80 | |
items: | |
build: ./items/src/Chamook.Items | |
ports: |
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 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 [ |
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
struct RGB: Decodable { | |
var red: Int | |
var green: Int | |
var blue: Int | |
} | |
struct Colour: Decodable { | |
var id: String | |
var name: String | |
var hex: 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
version: "3" | |
services: | |
colours: | |
build: ./colours/src/Chamook.Colours | |
ports: | |
- 8081:80 | |
items: | |
build: ./items/src/Chamook.Items | |
ports: |
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 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)); |
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 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 } |
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
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" | |
} |
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
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 |
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
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 | |
... |
NewerOlder