Is it possible to call Rx extension methods with lambdas from within an IronPython script?

Can someone please explain this really strange observation to me?

I am trying to call Rx extension methods from within IronPython, and this is just not possible. I swallowed this to a simple example:

import clr clr.AddReference("System.Core") from System.Linq import Enumerable def process(value): return Enumerable.Select(value, lambda x:x) 

In this case, we start with normal LINQ. If I call the process function from my hosting environment using an array or any other IEnumerable object, it works completely fine.

So, I tried to simply replace the references to using Observable extension methods as follows:

 import clr clr.AddReference("System.Reactive.Linq") from System.Reactive.Linq import Observable def process(value): return Observable.Select(value, lambda x:x) 

In this case, if I call the process function with an IObservable object, the call crashes with an ugly error message:

expected IObservable[object], got Select[int, int]

Has anyone hit something like this? Did I miss something? Is there any special hack to make Enumerable work with lambda delegates that is not Observable ? I must admit that I'm completely puzzled here.

By the way, just like a health check, the following example works just fine:

 import clr clr.AddReference("System.Reactive.Linq") from System.Reactive.Linq import Observable def process(value): return Observable.Sum(value) 

I wanted to leave it there so that it was clear that the problem was indeed in calling the Observable.Select method.

+6
source share
1 answer

Part of the problem that I suspect is that the methods are overloaded. The IronPython runtime will do its best to find the best overload, but it can sometimes make a mistake. You may need to help eliminate congestion.

From the error message, it seems that you are trying to call it on the IObservable<int> . It seems that overload resolution does not work here, and he tries to call it Observable.Select<object, object>() . You should provide some clues about which overload you want to use.

 def process(value): return Observable.Select[int,int](value, Func[int,int](lambda x:x)) 
+2
source

Source: https://habr.com/ru/post/1014086/


All Articles