Skip to content

Instantly share code, notes, and snippets.

@Neftedollar
Forked from atsapura/Srtp and Records.fs
Created June 5, 2019 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neftedollar/cf226e56273e7a91efb9f6771b674e73 to your computer and use it in GitHub Desktop.
Save Neftedollar/cf226e56273e7a91efb9f6771b674e73 to your computer and use it in GitHub Desktop.
type Test =
{ EntityId: string }
type Test2 =
{ EntityId: string
Name: string
Length: int }
let inline (|HasEntityId|) x =
fun () -> (^a : (member EntityId: string) x)
let inline entityId (HasEntityId f) = f()
let inline (|HasName|) n =
fun () -> (^a : (member Name: string) n)
let inline name (HasName f) = f()
let inline test2f (HasName n & HasEntityId id) = sprintf "name %s id %s" (n()) (id())
let test2 = {Test2.EntityId = "123"; Name = "123"; Length = 2}
let a = entityId { EntityId = "123" }
let b = entityId test2
let c = name test2
let d = test2f test2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment