Created
August 13, 2019 19:10
-
-
Save medigor/696dc378c31a4d8be9201a87cf4ea9d4 to your computer and use it in GitHub Desktop.
This file contains 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
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