Created
September 14, 2020 10:00
-
-
Save kos59125/d61fcabde9853680170787e7d87326d4 to your computer and use it in GitHub Desktop.
コンピュテーション式でセットアップ
This file contains hidden or 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 ServerSettings = { | |
Host : string | |
Port : int | |
} | |
type ServerSettingsBuilder() = | |
member _.Yield (_) = None, None | |
member _.Run((host, port)) = { Host = Option.get host; Port = Option.get port } | |
[<CustomOperation("host")>] | |
member _.SetHost ((_:string option, port:int option), host:string) = Some(host), port | |
[<CustomOperation("port")>] | |
member _.SetPort ((host:string option, _:int option), port:int) = host, Some(port) | |
let server = ServerSettingsBuilder() | |
type WebAppSettings = { | |
RdbServer : ServerSettings | |
CacheServer : ServerSettings | |
} | |
type WebAppSettingsBuilder() = | |
member _.Yield (_) = None, None | |
member _.Run((rdb, cache)) = { RdbServer = Option.get rdb; CacheServer = Option.get cache } | |
[<CustomOperation("rdb")>] | |
member _.SetRdb ((_:ServerSettings option, c:ServerSettings option), r:ServerSettings) = Some(r), c | |
[<CustomOperation("cache")>] | |
member _.SetCache ((r:ServerSettings option, _:ServerSettings option), c:ServerSettings) = r, Some(c) | |
let webapp = WebAppSettingsBuilder() | |
webapp { | |
rdb (server { | |
host "localhost" | |
port 1433 | |
}) | |
cache (server { | |
host "localhost" | |
port 6379 | |
}) | |
} | |
|> printfn "%A" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment