Skip to content

Commit

Permalink
Support + operator for adding items to the ImmutableCollection (#38)
Browse files Browse the repository at this point in the history
* Support + operator for adding items to the ImmutableCollection.
  • Loading branch information
Corniel committed Jun 7, 2023
1 parent 0eb58ba commit d1d6e4a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/Qowaiv.DomainModel/Collections/ImmutableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public ImmutableCollection Add(object? item)
/// <inheritdoc />
[Pure]
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

/// <summary>Adds an item to the collection.</summary>
/// <remarks>
/// Syntactic sugar.
/// </remarks>
public static ImmutableCollection operator +(ImmutableCollection collection, object item)
=> Guard.NotNull(collection, nameof(collection)).Add(item);
}
17 changes: 7 additions & 10 deletions src/Qowaiv.DomainModel/Collections/Then.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,22 @@ internal Then(bool done, ImmutableCollection item)
/// <inheritdoc />
public int Count => Items.Count;

/// <summary>Creates a new <see cref="ImmutableCollection"/> with the added items.</summary>
/// <summary>Creates a new <see cref="ImmutableCollection"/> with the added item(s).</summary>
/// <param name="item">
/// The item(s) to add.
/// </param>
/// <remarks>
/// Null, and null items are ignored.
/// </remarks>
[Pure]
public ImmutableCollection Add(params object?[] items) => Add<object[]>(items!);
public ImmutableCollection Add(object? item) => Items.Add(item!);

/// <summary>Creates a new <see cref="ImmutableCollection"/> with the added item(s).</summary>
/// <param name="item">
/// The item(s) to add.
/// </param>
/// <typeparam name="TItem">
/// The type of the item(s).
/// </typeparam>
/// <summary>Creates a new <see cref="ImmutableCollection"/> with the added items.</summary>
/// <remarks>
/// Null, and null items are ignored.
/// </remarks>
[Pure]
public ImmutableCollection Add<TItem>(TItem? item) where TItem : class => Items.Add(item);
public ImmutableCollection AddRange(params object?[]? items) => Add(items);

/// <summary>Adds else-if condition.</summary>
[Pure]
Expand Down
4 changes: 1 addition & 3 deletions src/Qowaiv.DomainModel/EventDispatcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Qowaiv.DomainModel.Reflection;

namespace Qowaiv.DomainModel;
namespace Qowaiv.DomainModel;

/// <summary>Factory for creating <see cref="ExpressionCompilingEventDispatcher{TDispatcher}"/>'s.</summary>
public interface EventDispatcher

Check warning on line 4 in src/Qowaiv.DomainModel/EventDispatcher.cs

View workflow job for this annotation

GitHub Actions / build

Interface names should begin with I

Check warning on line 4 in src/Qowaiv.DomainModel/EventDispatcher.cs

View workflow job for this annotation

GitHub Actions / build

Interface names should begin with I

Check warning on line 4 in src/Qowaiv.DomainModel/EventDispatcher.cs

View workflow job for this annotation

GitHub Actions / build

Interface names should begin with I

Check warning on line 4 in src/Qowaiv.DomainModel/EventDispatcher.cs

View workflow job for this annotation

GitHub Actions / build

Interface names should begin with I
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Qowaiv.DomainModel.UnitTests;

namespace Collections.Immutable_Collection_specs;
namespace Collections.Immutable_Collection_specs;

internal static class Help
{
Expand Down Expand Up @@ -79,6 +77,15 @@ public void Does_not_effect_shared_subs()
first.Should().BeEquivalentTo(new[] { 1, 2, 4, 8, 16 });
second.Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5 });
}

[Test]
public void with_plus_operator()
{
var collection = ImmutableCollection.Empty;
collection += 3;
collection += new[] { 6, 9 };
collection.Should().BeEquivalentTo(new[] { 3, 6, 9 });
}
}

public class If_not_true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Qowaiv.DomainModel.UnitTests;

namespace Commands.CommandProcessor_specs;
namespace Commands.CommandProcessor_specs;

interface CommandHandler<TCommand> { Task<Result<string>> Handle(TCommand command); }
interface CancelableCommandHandler<TCommand> { Task<Result<string>> Handle(TCommand command, CancellationToken token); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Qowaiv;
using Qowaiv.DomainModel;
using Qowaiv.DomainModel;
using Qowaiv.DomainModel.UnitTests.Models;

namespace Event_sourced_aggregate_specs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Qowaiv.DomainModel.TestTools;
using Qowaiv.DomainModel.UnitTests;
using Qowaiv.Globalization;
using TestEvents;

namespace Qowaiv.DomainModel.UnitTests.TestTools
{
{
public class AggregateRootAssertTest
{
[Test]
Expand Down

0 comments on commit d1d6e4a

Please sign in to comment.