Created
April 21, 2016 16:59
-
-
Save mastoj/384db91ceda66c149b84d3eeb53484eb 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
open Microsoft.FSharp.Reflection | |
module MA = | |
type A = { AStr: string} | |
type B = { BInt: int} | |
type private DU = | |
| A of A | |
| B of B | |
type Wrapper = | |
private { Items: DU list} | |
with static member init() = { Items = List.Empty} | |
let getSomethingFromDU a = | |
FSharpValue.GetUnionFields(a, typeof<DU>, true) | |
|> snd | |
let getSomething a = | |
a.Items |> List.map getSomethingFromDU | |
let createA w = { w with Items = (A {AStr = "Hello"})::w.Items} | |
let createB w = { w with Items = (B {BInt = 5})::w.Items} | |
module Tests = | |
open MA | |
let run() = | |
Wrapper.init() | |
|> createA | |
|> createB | |
|> getSomething | |
|> printfn "%A" | |
Tests.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment