Skip to content

Instantly share code, notes, and snippets.

@mastoj
Created April 21, 2016 16:59
Show Gist options
  • Save mastoj/384db91ceda66c149b84d3eeb53484eb to your computer and use it in GitHub Desktop.
Save mastoj/384db91ceda66c149b84d3eeb53484eb to your computer and use it in GitHub Desktop.
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