Last active
December 15, 2015 09:49
-
-
Save mausch/5241729 to your computer and use it in GitHub Desktop.
Anonymous iterators in C# with Ix
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
var hello = ""; | |
var enumerable = | |
EnumerableEx.Create<int>(async Yield => { | |
await Yield.Return(100); | |
await Yield.Return(200); | |
hello = "hello world"; | |
await Yield.Return(300); | |
}); | |
Console.WriteLine(enumerable.ElementAt(1)); // 200 | |
Console.WriteLine(hello); // empty | |
Console.WriteLine(enumerable.ElementAt(2)); // 300 | |
Console.WriteLine(hello); // "hello world" |
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
let mutable hello = "" | |
let enumerable = | |
seq { | |
yield 100 | |
yield 200 | |
hello <- "hello world" | |
yield 300 | |
} | |
printfn "%d" (enumerable.ElementAt 1) // 200 | |
printfn "%s" hello // empty | |
printfn "%d" (enumerable.ElementAt 2) // 300 | |
printfn "%s" hello // "hello world" |
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
Dim hello = "" | |
Dim enumerable = | |
Iterator Function() | |
Yield 100 | |
Yield 200 | |
hello = "hello world" | |
Yield 300 | |
End Function | |
Console.WriteLine(enumerable().ElementAt(1)) ' 200 | |
Console.WriteLine(hello) ' empty | |
Console.WriteLine(enumerable().ElementAt(2)) ' 300 | |
Console.WriteLine(hello) ' "hello world" |
I copied the code directly from the diff Erik posted: http://rx.codeplex.com/SourceControl/changeset/8f1e73bca96e474ea73f40de1af9b8fc9307fddb , it worked ok.
I didn't use the Nuget package (didn't know this was released). It looks like they forgot to set one of those security rules/attributes that I never understand ( http://blogs.msdn.com/b/shawnfa/archive/2009/11/12/differences-between-the-security-rule-sets.aspx ).
Unhandled Exception: System.TypeLoadException: Inheritance security rules violated while overriding member: 'System.Linq.Yielder`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
at System.Linq.EnumerableEx.<Create>d__a6`1.MoveNext()
at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)
at ConsoleApplication21.Program.Main(String[] args) in g:\prg\ConsoleApplication21\ConsoleApplication21\Program.cs:line 15
Created a new issue: http://rx.codeplex.com/workitem/20 , going to sleep
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got following
InnerException
on line 10 while using Ix-Main 0.9.0.2:StackTrace
at System.Linq.EnumerableEx.d__a6
1.MoveNext() at System.Linq.Enumerable.ElementAt[TSource](IEnumerable
1 source, Int32 index)at UserQuery.RunUserAuthoredQuery() in Source System.Interactive
Message
Inheritance security rules violated while overriding member: 'System.Linq.Yielder`1.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
TypeName
System.Linq.Yielder`1.UnsafeOnCompleted(System.Action)