Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# badbuzz #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions CSharp/C-xC-c.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

await foreach (var _ in await await await await await await await 0_0) ;

static class Ext
{
public static FizzBuzzEnumerator GetAsyncEnumerator(this int i) => new(i);

public static FizzBuzzAwaiter GetAwaiter(this int depth) => new(depth);

public static void FizzBuzz(int i) => Console.WriteLine((i % 15) switch
{
0 => "FizzBuzz",
5 or 10 => "Buzz",
3 or 6 or 9 or 12 => "Fizz",
_ => i.ToString()
});
}

record FizzBuzzAwaiter(int Depth) : INotifyCompletion
{
public bool IsCompleted => true;

public int GetResult()
{
Ext.FizzBuzz(Depth);

return Depth + 1;
}

public void OnCompleted(Action continuation)
{
}
}

sealed class FizzBuzzEnumerator
{
public int Current { get; private set; }

public FizzBuzzEnumerator(int current) => Current = current;

public ValueTask<bool> MoveNextAsync()
{
Ext.FizzBuzz(Current);

return new(Current++ < 100);
}
}