Skip to content

Instantly share code, notes, and snippets.

@medigor
Created August 13, 2019 19:10
Show Gist options
  • Save medigor/696dc378c31a4d8be9201a87cf4ea9d4 to your computer and use it in GitHub Desktop.
Save medigor/696dc378c31a4d8be9201a87cf4ea9d4 to your computer and use it in GitHub Desktop.
module Tests
open System
open Xunit
type IFoo =
abstract Foo1 : string
abstract Foo2 : unit -> string
abstract Foo3 : string -> string
let useIFoo (p: IFoo) =
Console.WriteLine p.Foo1
Console.WriteLine (p.Foo2())
Console.WriteLine (p.Foo3("xyz"))
type Int32 with
member x.AsIFoo() =
{ new IFoo with
member this.Foo1 = "1-" + x.ToString()
member this.Foo2() = "2-" + x.ToString()
member this.Foo3(p) = "3-" + p + "-" + x.ToString()}
type String with
member x.AsIFoo() =
{ new IFoo with
member this.Foo1 = "1-" + x
member this.Foo2() = "2-" + x
member this.Foo3(p) = "3-" + p + "-" + x}
[<Fact>]
let ``Use IFoo`` () =
useIFoo <| (45).AsIFoo()
useIFoo <| "bee".AsIFoo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment