Skip to content

Commit

Permalink
IgnoreElements
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 27, 2023
1 parent ee71370 commit f2f2e33
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
13 changes: 13 additions & 0 deletions sandbox/ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@

Enumerable.Range(1, 10).Cast<int>();


var a = range.Publish();


// BehaviourSubject -> ReactiveProperty
// ReplaySubject




a.Connect();


// range.Catch(
// range.Append(

Expand Down
1 change: 1 addition & 0 deletions src/R3/Operators/CombineLatest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//namespace R3;

//TODO:not yet implemented.
//public static partial class EventExtensions
//{
// public static Event<TResult> CombineLatest<TLeft, TRight, TResult>(
Expand Down
1 change: 1 addition & 0 deletions src/R3/Operators/Delay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace R3;

//TODO:not yet implemented.
public static partial class ObservableExtensions
{
//public static Event<T> Delay<T>(this Event<T> source, TimeSpan dueTime, TimeProvider timeProvider)
Expand Down
34 changes: 34 additions & 0 deletions src/R3/Operators/IgnoreElements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace R3;

public static partial class ObservableExtensions
{
public static Observable<T> IgnoreElements<T>(this Observable<T> source)
{
return new IgnoreElements<T>(source);
}
}

internal sealed class IgnoreElements<T>(Observable<T> source) : Observable<T>
{
protected override IDisposable SubscribeCore(Observer<T> observer)
{
return source.Subscribe(new _IgnoreElements(observer));
}

sealed class _IgnoreElements(Observer<T> observer) : Observer<T>
{
protected override void OnNextCore(T value)
{
}

protected override void OnErrorResumeCore(Exception error)
{
observer.OnErrorResume(error);
}

protected override void OnCompletedCore(Result result)
{
observer.OnCompleted(result);
}
}
}
1 change: 0 additions & 1 deletion src/R3/Operators/OfType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ protected override void OnCompletedCore(Result result)
}
}
}

3 changes: 3 additions & 0 deletions src/R3/Operators/_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public static partial class ObservableExtensions

// return tasks:
// All, Any, Contains, SequenceEqual, IsEmpty, MaxBy, MinBy, ToDictionary, ToLookup,

// Multicast
// Multicast, Publish, Replay, RefCount, Share(Publish().RefCount()), AutoConnect
}
22 changes: 22 additions & 0 deletions tests/R3.Tests/OperatorTests/IgnoreElementsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace R3.Tests.OperatorTests;

public class IgnoreElementsTest
{
[Fact]
public void Test()
{
var subject = new Subject<int>();
using var list = subject.IgnoreElements().ToLiveList();

subject.OnNext(10);
subject.OnNext(20);
subject.OnNext(30);

list.AssertEqual([]);
list.AssertIsNotCompleted();

subject.OnCompleted();

list.AssertIsCompleted();
}
}

0 comments on commit f2f2e33

Please sign in to comment.