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
[MemoryDiagnoser] | |
public class SwitchWithBlockingSources | |
{ | |
public readonly static IAsyncEnumerable<IAsyncEnumerable<int>> source = AsyncEnumerable | |
.Range(0, 1000) | |
.SelectAwait(async i => | |
{ | |
await Task.Yield(); | |
return AsyncEnumerable | |
.Range(0, 1000) |
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
[MemoryDiagnoser] | |
public class SwitchWithNonBlockingSources | |
{ | |
public readonly static IAsyncEnumerable<IAsyncEnumerable<int>> source = AsyncEnumerable | |
.Range(0, 1000) | |
.Select(i => AsyncEnumerable.Range(0, 1000)); | |
[Benchmark] | |
public async ValueTask<int> IterativeSingleLogicalThread() | |
{ |
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
namespace AsyncEnumerableSwitchSpike; | |
internal static class SwitchExtension | |
{ | |
public static async IAsyncEnumerable<T> Switch<T>(this IAsyncEnumerable<IAsyncEnumerable<T>> sequences) | |
{ | |
IAsyncEnumerator<IAsyncEnumerable<T>>? currentOuterEnumerator = sequences.GetAsyncEnumerator(); | |
IAsyncEnumerator<T>? currentInnerEnumerator = null; | |
try |
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
// Written as a reply to https://twitter.com/buhakmeh/status/1577738711013335040 | |
// (C) 2022 I D Griffiths | |
// EnumerableEx from System.Interactive | |
IEnumerable<BigInteger> FibonnaciEndless() => EnumerableEx.Generate( | |
(i: new BigInteger(0), n: new BigInteger(1)), | |
_ => true, | |
s => (s.n, s.i + s.n), | |
s => s.i); |
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
// Written as a reply to https://twitter.com/buhakmeh/status/1577738711013335040 | |
// (C) 2022 I D Griffiths | |
IEnumerable<BigInteger> FibonnaciEndless() | |
{ | |
BigInteger i = 0, n = 1; | |
while (true) | |
{ | |
yield return i; | |
(i, n) = (n, i + n); |
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
public class Person | |
{ | |
// This gets rid of the CS8618 warning, but it is | |
// A BAD IDEA! | |
public string FavouriteColour { get; set; } = ""; | |
} |
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 o = (JObject)JToken.Parse(text); | |
bool hasItem = o.ContainsKey("item"); |
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
if (JToken.Parse(text) is JObject o) | |
{ | |
bool hasItem = o.ContainsKey("item"); | |
Console.WriteLine(hasItem); | |
} |
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 o = JToken.Parse(text) as JObject; | |
if (o != null) | |
{ | |
Console.WriteLine("item is " + (o.ContainsKey("item") ? "present" : "absent")); | |
} | |
bool hasItem = o != null ? o.ContainsKey("item") : false; | |
bool? itemPresence = o?.ContainsKey("item"); |
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 o = JToken.Parse(text) as JObject; | |
bool hasItem = o.ContainsKey("item"); |
NewerOlder