Created
July 5, 2022 17:55
-
-
Save baronfel/bf926788257b88372a90f1e66eb24f07 to your computer and use it in GitHub Desktop.
attempted .Add wrapper
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
[<Struct>] | |
type AddWrapper< 't, 'x >(item: 't, adder: 'x -> unit) = | |
member inline _.Delay(f) = f() | |
// incorrect, but just doing it for now | |
member inline _.Combine(left, right) = left | |
member _.Yield(o) = | |
adder o | |
item | |
member _.Zero () = item | |
// causes the CE to return the collection, so it looks like part of the constructor | |
member _.Run (item: 't) = item | |
let inline wrap< ^t, ^item when ^t : (member Add: ^item -> unit)> (t: ^t) = AddWrapper< 't, 'item >(t, fun x -> (^t : (member Add: ^item -> unit) (t, x))) | |
#r "nuget: System.CommandLine, 2.0.0-beta4.22272.1" | |
open System.CommandLine | |
let command = wrap<_, _> (Command("foo")) { // uncomment each of the below lines to see it work | |
// Option<string>("blah") | |
// Argument<int>("repeats") | |
Command("bollocks") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment