Skip to content

Instantly share code, notes, and snippets.

@baronfel
Created July 5, 2022 17:55
Show Gist options
  • Save baronfel/bf926788257b88372a90f1e66eb24f07 to your computer and use it in GitHub Desktop.
Save baronfel/bf926788257b88372a90f1e66eb24f07 to your computer and use it in GitHub Desktop.
attempted .Add wrapper
[<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