2

I have the following code working code that I derived from a Pluralsight video from Mark Seeman. I do not understand how the last line works.

let sharpObjectCollection = ConcurrentBag<Envelope<SharpObject>>()
let sharpObjectSubject = new Subjects.Subject<Envelope<SharpObject>>()
sharpObjectSubject.Subscribe sharpObjectCollection.Add |> ignore

Looking through the documentation for Subscribe, I see that it takes an IObserver as an argument, but I am passing it the ConcurrentBag.Add method.

What is going on here? Is this a feature of F#? Can I do this in c# too?

Phillip Scott Givens
  • 5,256
  • 4
  • 32
  • 54

1 Answers1

5

It looks like it is calling this extension method which defines an overload of Subscribe which takes an Action<T> onNext handler. You can also do this in C#:

var bag = new ConcurrentBag<Envelope<SharpObject>>();
var subject = new Subject<Envelope<SharpObject>>();
subject.Subscribe(bag.Add);
Lee
  • 142,018
  • 20
  • 234
  • 287