Skip to content

Commit

Permalink
remove namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 13, 2023
1 parent 31793f0 commit 7b6d3c0
Show file tree
Hide file tree
Showing 27 changed files with 1,844 additions and 1,952 deletions.
50 changes: 23 additions & 27 deletions src/R3/Factories/Empty.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
namespace R3
namespace R3;

public static partial class Event
{
public static partial class Event
public static Event<TMessage, Unit> Empty<TMessage>()
{
public static Event<TMessage, Unit> Empty<TMessage>()
{
return R3.Factories.Empty<TMessage>.Instance;
}
return R3.Empty<TMessage>.Instance;
}

public static Event<TMessage, Unit> Empty<TMessage>(TimeProvider timeProvider)
{
return ReturnOnCompleted<TMessage, Unit>(default, timeProvider);
}
public static Event<TMessage, Unit> Empty<TMessage>(TimeProvider timeProvider)
{
return ReturnOnCompleted<TMessage, Unit>(default, timeProvider);
}

public static Event<TMessage, Unit> Empty<TMessage>(TimeSpan dueTime, TimeProvider timeProvider)
{
return ReturnOnCompleted<TMessage, Unit>(default, dueTime, timeProvider);
}
public static Event<TMessage, Unit> Empty<TMessage>(TimeSpan dueTime, TimeProvider timeProvider)
{
return ReturnOnCompleted<TMessage, Unit>(default, dueTime, timeProvider);
}
}

namespace R3.Factories
internal sealed class Empty<TMessage> : Event<TMessage, Unit>
{
internal sealed class Empty<TMessage> : Event<TMessage, Unit>
{
// singleton
public static readonly Empty<TMessage> Instance = new Empty<TMessage>();
// singleton
public static readonly Empty<TMessage> Instance = new Empty<TMessage>();

protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
{
subscriber.OnCompleted(default);
return Disposable.Empty;
}
protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
{
subscriber.OnCompleted(default);
return Disposable.Empty;
}

Empty()
{
Empty()
{

}
}
}
34 changes: 15 additions & 19 deletions src/R3/Factories/Never.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
namespace R3
namespace R3;

public static partial class Event
{
public static partial class Event
// Never
public static Event<TMessage, TComplete> Never<TMessage, TComplete>()
{
// Never
public static Event<TMessage, TComplete> Never<TMessage, TComplete>()
{
return R3.Factories.Never<TMessage, TComplete>.Instance;
}
return R3.Never<TMessage, TComplete>.Instance;
}
}

namespace R3.Factories
internal sealed class Never<TMessage, TComplete> : Event<TMessage, TComplete>
{
internal sealed class Never<TMessage, TComplete> : Event<TMessage, TComplete>
{
// singleton
public static readonly Never<TMessage, TComplete> Instance = new Never<TMessage, TComplete>();
// singleton
public static readonly Never<TMessage, TComplete> Instance = new Never<TMessage, TComplete>();

Never()
{
Never()
{

}
}

protected override IDisposable SubscribeCore(Subscriber<TMessage, TComplete> subscriber)
{
return Disposable.Empty;
}
protected override IDisposable SubscribeCore(Subscriber<TMessage, TComplete> subscriber)
{
return Disposable.Empty;
}
}
88 changes: 42 additions & 46 deletions src/R3/Factories/Range.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,68 @@
namespace R3
namespace R3;

public static partial class Event
{
public static partial class Event
// no scheduler(TimeProvider) overload

public static Event<int, Unit> Range(int start, int count)
{
// no scheduler(TimeProvider) overload
long max = ((long)start) + count - 1;
if (count < 0 || max > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

public static Event<int, Unit> Range(int start, int count)
if (count == 0)
{
long max = ((long)start) + count - 1;
if (count < 0 || max > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(count));
}
return Empty<int>();
}

if (count == 0)
{
return Empty<int>();
}
return new Range(start, count);
}

return new R3.Factories.Range(start, count);
public static Event<int, Unit> Range(int start, int count, CancellationToken cancellationToken)
{
long max = ((long)start) + count - 1;
if (count < 0 || max > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

public static Event<int, Unit> Range(int start, int count, CancellationToken cancellationToken)
if (count == 0)
{
long max = ((long)start) + count - 1;
if (count < 0 || max > int.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

if (count == 0)
{
return Empty<int>();
}

return new R3.Factories.RangeC(start, count, cancellationToken);
return Empty<int>();
}

return new RangeC(start, count, cancellationToken);
}
}

namespace R3.Factories
internal sealed class Range(int start, int count) : Event<int, Unit>
{
internal sealed class Range(int start, int count) : Event<int, Unit>
protected override IDisposable SubscribeCore(Subscriber<int, Unit> subscriber)
{
protected override IDisposable SubscribeCore(Subscriber<int, Unit> subscriber)
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++)
{
subscriber.OnNext(start + i);
}
subscriber.OnCompleted(default);
return Disposable.Empty;
subscriber.OnNext(start + i);
}
subscriber.OnCompleted(default);
return Disposable.Empty;
}
}

internal sealed class RangeC(int start, int count, CancellationToken cancellationToken) : Event<int, Unit>
internal sealed class RangeC(int start, int count, CancellationToken cancellationToken) : Event<int, Unit>
{
protected override IDisposable SubscribeCore(Subscriber<int, Unit> subscriber)
{
protected override IDisposable SubscribeCore(Subscriber<int, Unit> subscriber)
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++)
if (cancellationToken.IsCancellationRequested)
{
if (cancellationToken.IsCancellationRequested)
{
return Disposable.Empty;
}
subscriber.OnNext(start + i);
return Disposable.Empty;
}
subscriber.OnCompleted(default);
return Disposable.Empty;
subscriber.OnNext(start + i);
}
subscriber.OnCompleted(default);
return Disposable.Empty;
}
}
86 changes: 41 additions & 45 deletions src/R3/Factories/Repeat.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
namespace R3
namespace R3;

public static partial class Event
{
public static partial class Event
// no scheduler(TimeProvider) overload
// no infinitely overload

public static Event<TMessage, Unit> Repeat<TMessage>(TMessage value, int count)
{
// no scheduler(TimeProvider) overload
// no infinitely overload
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

public static Event<TMessage, Unit> Repeat<TMessage>(TMessage value, int count)
if (count == 0)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}
return Empty<TMessage>();
}

if (count == 0)
{
return Empty<TMessage>();
}
return new Repeat<TMessage>(value, count);
}

return new Repeat<TMessage>(value, count);
public static Event<TMessage, Unit> Repeat<TMessage>(TMessage value, int count, CancellationToken cancellationToken)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

public static Event<TMessage, Unit> Repeat<TMessage>(TMessage value, int count, CancellationToken cancellationToken)
if (count == 0)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

if (count == 0)
{
return Empty<TMessage>();
}

return new RepeatC<TMessage>(value, count, cancellationToken);
return Empty<TMessage>();
}

return new RepeatC<TMessage>(value, count, cancellationToken);
}
}

namespace R3.Factories
internal sealed class Repeat<TMessage>(TMessage value, int count) : Event<TMessage, Unit>
{
internal sealed class Repeat<TMessage>(TMessage value, int count) : Event<TMessage, Unit>
protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
{
protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++)
{
subscriber.OnNext(value);
}
subscriber.OnCompleted(default);
return Disposable.Empty;
subscriber.OnNext(value);
}
subscriber.OnCompleted(default);
return Disposable.Empty;
}
}

internal sealed class RepeatC<TMessage>(TMessage value, int count, CancellationToken cancellationToken) : Event<TMessage, Unit>
internal sealed class RepeatC<TMessage>(TMessage value, int count, CancellationToken cancellationToken) : Event<TMessage, Unit>
{
protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
{
protected override IDisposable SubscribeCore(Subscriber<TMessage, Unit> subscriber)
for (int i = 0; i < count; i++)
{
for (int i = 0; i < count; i++)
if (cancellationToken.IsCancellationRequested)
{
if (cancellationToken.IsCancellationRequested)
{
return Disposable.Empty;
}
subscriber.OnNext(value);
return Disposable.Empty;
}
subscriber.OnCompleted(default);
return Disposable.Empty;
subscriber.OnNext(value);
}
subscriber.OnCompleted(default);
return Disposable.Empty;
}
}
Loading

0 comments on commit 7b6d3c0

Please sign in to comment.