Skip to content

Commit

Permalink
renamed MatchSome/MatchNone to IfSome/IfNone
Browse files Browse the repository at this point in the history
  • Loading branch information
duffleit committed Oct 11, 2016
1 parent 6aa4fb0 commit 297bf87
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 64 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var displayName = optional.Match(
)
```

Beside ``Match()`` there are provided more specific methods called ``MatchSome()`` and ``MatchNone()``. They only take one action.
Beside ``Match()`` there are provided more specific methods called ``IfSome()`` and ``IfNone()``. They only take one action.

## Mapping Optionals

Expand Down Expand Up @@ -147,7 +147,7 @@ Optional
```

A joined Optional evaluates to none as soon as a __None__-Optional gets joined.
_Fluent Optionals_ let you join up to 7 Optionals, and beside ``Match()`` also ``MatchSome()``, ``MatchNone()``, ``IsSome`` and ``IsNone`` can be called.
_Fluent Optionals_ let you join up to 7 Optionals, and beside ``Match()`` also ``IfSome()``, ``IfNone()``, ``IsSome`` and ``IsNone`` can be called.

## IEnumerable-Extensions

Expand Down
10 changes: 5 additions & 5 deletions fluentOptionals.Tests/Linq/OptionalEnumerableExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void FirstOrNone_WhenListWithMultipleItemsIsGiven_ThenSomeOfFirstElementG
var first = new List<int> {1, 2, 3}.FirstOrNone();

first.ShouldBeSome();
first.MatchSome(i => i.Should().Be(1));
first.IfSome(i => i.Should().Be(1));
}


Expand All @@ -33,7 +33,7 @@ public void FirstOrNone_WhenListWithSingleItemIsGiven_ThenSomeOfSingleElementGet
var first = new List<int> { 10 }.FirstOrNone();

first.ShouldBeSome();
first.MatchSome(i => i.Should().Be(10));
first.IfSome(i => i.Should().Be(10));
}

#endregion
Expand All @@ -52,7 +52,7 @@ public void LastOrNone_WhenListWithMultipleItemsIsGiven_ThenSomeOfLastElementGet
var last = new List<int> { 1, 2, 3 }.LastOrNone();

last.ShouldBeSome();
last.MatchSome(i => i.Should().Be(3));
last.IfSome(i => i.Should().Be(3));
}


Expand All @@ -62,7 +62,7 @@ public void LastOrNone_WhenListWithSingleItemIsGiven_ThenSomeOfSingleElementGets
var last = new List<int> { 10 }.LastOrNone();

last.ShouldBeSome();
last.MatchSome(i => i.Should().Be(10));
last.IfSome(i => i.Should().Be(10));
}

#endregion
Expand All @@ -88,7 +88,7 @@ public void SingleOrNone_WhenListWithSingleItemIsGiven_ThenSomeOfSingleElementGe
var single = new List<int> { 10 }.SingleOrNone();

single.ShouldBeSome();
single.MatchSome(i => i.Should().Be(10));
single.IfSome(i => i.Should().Be(10));
}

#endregion
Expand Down
38 changes: 19 additions & 19 deletions fluentOptionals.Tests/Optionals/Optional1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,53 @@ public void Setup()
_none = Optional.None<int>();
}

#region MatchSome
#region IfSome

[Test]
public void MatchSome_HandleIsNotCalledOnNone()
public void IfSome_HandleIsNotCalledOnNone()
{
var handleCalled = false;
_none.MatchSome(_ => handleCalled = true);
_none.IfSome(_ => handleCalled = true);

handleCalled.Should().Be(false);
}

[Test]
public void MatchSome_HandleIsCalledOnSome()
public void IfSome_HandleIsCalledOnSome()
{
var handleCalled = false;
_some.MatchSome(_ => handleCalled = true);
_some.IfSome(_ => handleCalled = true);

handleCalled.Should().Be(true);
}

[Test]
public void MatchSome_HandleReturnsRightValue()
public void IfSome_HandleReturnsRightValue()
{
var returnedValue = 0;
_some.MatchSome(i => returnedValue = i);
_some.IfSome(i => returnedValue = i);

returnedValue.Should().Be(1);
}

#endregion

#region MatchNone
#region IfNone

[Test]
public void MatchNone_HandleIsNotCalledOnSome()
public void IfNone_HandleIsNotCalledOnSome()
{
var handleCalled = false;
_some.MatchNone(() => handleCalled = true);
_some.IfNone(() => handleCalled = true);

handleCalled.Should().Be(false);
}

[Test]
public void MatchNone_HandleIsCalledOnNone()
public void IfNone_HandleIsCalledOnNone()
{
var handleCalled = false;
_none.MatchNone(() => handleCalled = true);
_none.IfNone(() => handleCalled = true);

handleCalled.Should().Be(true);
}
Expand All @@ -73,26 +73,26 @@ public void MatchNone_HandleIsCalledOnNone()
#region ValueOr

[Test]
public void MatchNone_WhenOptionalIsNone_ThenValueFromHandleGetsReturned()
public void IfNone_WhenOptionalIsNone_ThenValueFromHandleGetsReturned()
{
_none.ValueOr(() => 20).Should().Be(20);
}

[Test]
public void MatchNone_WhenOptionalIsNone_ThenValueGetsReturned()
public void IfNone_WhenOptionalIsNone_ThenValueGetsReturned()
{
_none.ValueOr(20).Should().Be(20);
}


[Test]
public void MatchNone_WhenOptionalIsSome_ThenValueFromHandleIsIgnored()
public void IfNone_WhenOptionalIsSome_ThenValueFromHandleIsIgnored()
{
_some.ValueOr(() => 20).Should().NotBe(20);
}

[Test]
public void MatchNone_WhenOptionalIsSome_ThenValueIsIgnored()
public void IfNone_WhenOptionalIsSome_ThenValueIsIgnored()
{
_some.ValueOr(20).Should().NotBe(20);
}
Expand Down Expand Up @@ -227,21 +227,21 @@ public void Shift_WhenNoneIsShifted_ThenNoneGetsReturned()
public void ImplicitOperator_NullGetsNone()
{
Optional<object> optional = (object) null;
optional.MatchSome(_ => Assert.Fail());
optional.IfSome(_ => Assert.Fail());
}

[Test]
public void ImplicitOperator_ValueTypeGetsSome()
{
Optional<int> optional = 15;
optional.MatchNone(Assert.Fail);
optional.IfNone(Assert.Fail);
}

[Test]
public void ImplicitOperator_ReferenceTypeGetsSome()
{
Optional<DateTime> optional = DateTime.Now;
optional.MatchNone(Assert.Fail);
optional.IfNone(Assert.Fail);
}

#endregion
Expand Down
8 changes: 4 additions & 4 deletions fluentOptionals.Tests/Optionals/Optional2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,25 @@ public void Match_WhenOneOptionalIsNone_ThenMatchReturnsNoneValue()
}

[Test]
public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
public void IfNone_WhenOneOptionalIsNone_ThenIfSomeHandleGetsCalled()
{
var noneHandleCalled = false;

Optional.From(1)
.Join(Optional.None<int>())
.MatchNone(() => noneHandleCalled = true);
.IfNone(() => noneHandleCalled = true);

noneHandleCalled.Should().BeTrue();
}

[Test]
public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
public void IfSome_WhenAllOptionalsAreSome_ThenIfSomeHandleGetsCalled()
{
var someHandleCalled = false;

Optional.From(1)
.Join(2)
.MatchSome((p1, p2) => someHandleCalled = true);
.IfSome((p1, p2) => someHandleCalled = true);

someHandleCalled.Should().BeTrue();
}
Expand Down
8 changes: 4 additions & 4 deletions fluentOptionals.Tests/Optionals/Optional3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,27 @@ public void Match_WhenOneOptionalIsNone_ThenMatchReturnsNoneValue()
}

[Test]
public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
public void IfNone_WhenOneOptionalIsNone_ThenIfSomeHandleGetsCalled()
{
var noneHandleCalled = false;

Optional.From(1)
.Join(2)
.Join(Optional.None<int>())
.MatchNone(() => noneHandleCalled = true);
.IfNone(() => noneHandleCalled = true);

noneHandleCalled.Should().BeTrue();
}

[Test]
public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
public void IfSome_WhenAllOptionalsAreSome_ThenIfSomeHandleGetsCalled()
{
var someHandleCalled = false;

Optional.From(1)
.Join(2)
.Join(3)
.MatchSome((p1, p2, p3) => someHandleCalled = true);
.IfSome((p1, p2, p3) => someHandleCalled = true);

someHandleCalled.Should().BeTrue();
}
Expand Down
8 changes: 4 additions & 4 deletions fluentOptionals.Tests/Optionals/Optional4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,29 @@ public void Match_WhenOneOptionalIsNone_ThenMatchReturnsNoneValue()
}

[Test]
public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
public void IfNone_WhenOneOptionalIsNone_ThenIfSomeHandleGetsCalled()
{
var noneHandleCalled = false;

Optional.From(1)
.Join(2)
.Join(3)
.Join(Optional.None<int>())
.MatchNone(() => noneHandleCalled = true);
.IfNone(() => noneHandleCalled = true);

noneHandleCalled.Should().BeTrue();
}

[Test]
public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
public void IfSome_WhenAllOptionalsAreSome_ThenIfSomeHandleGetsCalled()
{
var someHandleCalled = false;

Optional.From(1)
.Join(2)
.Join(3)
.Join(4)
.MatchSome((p1, p2, p3, p4) => someHandleCalled = true);
.IfSome((p1, p2, p3, p4) => someHandleCalled = true);

someHandleCalled.Should().BeTrue();
}
Expand Down
8 changes: 4 additions & 4 deletions fluentOptionals.Tests/Optionals/Optional5Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void Match_WhenOneOptionalIsNone_ThenMatchReturnsNoneValue()
}

[Test]
public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
public void IfNone_WhenOneOptionalIsNone_ThenIfSomeHandleGetsCalled()
{
var noneHandleCalled = false;

Expand All @@ -119,13 +119,13 @@ public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
.Join(3)
.Join(4)
.Join(Optional.None<int>())
.MatchNone(() => noneHandleCalled = true);
.IfNone(() => noneHandleCalled = true);

noneHandleCalled.Should().BeTrue();
}

[Test]
public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
public void IfSome_WhenAllOptionalsAreSome_ThenIfSomeHandleGetsCalled()
{
var someHandleCalled = false;

Expand All @@ -134,7 +134,7 @@ public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
.Join(3)
.Join(4)
.Join(5)
.MatchSome((p1, p2, p3, p4, p5) => someHandleCalled = true);
.IfSome((p1, p2, p3, p4, p5) => someHandleCalled = true);

someHandleCalled.Should().BeTrue();
}
Expand Down
8 changes: 4 additions & 4 deletions fluentOptionals.Tests/Optionals/Optional6Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void Match_WhenOneOptionalIsNone_ThenMatchReturnsNoneValue()
}

[Test]
public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
public void IfNone_WhenOneOptionalIsNone_ThenIfSomeHandleGetsCalled()
{
var noneHandleCalled = false;

Expand All @@ -126,13 +126,13 @@ public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
.Join(4)
.Join(5)
.Join(Optional.None<int>())
.MatchNone(() => noneHandleCalled = true);
.IfNone(() => noneHandleCalled = true);

noneHandleCalled.Should().BeTrue();
}

[Test]
public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
public void IfSome_WhenAllOptionalsAreSome_ThenIfSomeHandleGetsCalled()
{
var someHandleCalled = false;

Expand All @@ -142,7 +142,7 @@ public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
.Join(4)
.Join(5)
.Join(6)
.MatchSome((p1, p2, p3, p4, p5, p6) => someHandleCalled = true);
.IfSome((p1, p2, p3, p4, p5, p6) => someHandleCalled = true);

someHandleCalled.Should().BeTrue();
}
Expand Down
8 changes: 4 additions & 4 deletions fluentOptionals.Tests/Optionals/Optional7Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void Match_WhenOneOptionalIsNone_ThenMatchReturnsNoneValue()
}

[Test]
public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
public void IfNone_WhenOneOptionalIsNone_ThenIfSomeHandleGetsCalled()
{
var noneHandleCalled = false;

Expand All @@ -133,13 +133,13 @@ public void MatchNone_WhenOneOptionalIsNone_ThenMatchSomeHandleGetsCalled()
.Join(5)
.Join(6)
.Join(Optional.None<int>())
.MatchNone(() => noneHandleCalled = true);
.IfNone(() => noneHandleCalled = true);

noneHandleCalled.Should().BeTrue();
}

[Test]
public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
public void IfSome_WhenAllOptionalsAreSome_ThenIfSomeHandleGetsCalled()
{
var someHandleCalled = false;

Expand All @@ -150,7 +150,7 @@ public void MatchSome_WhenAllOptionalsAreSome_ThenMatchSomeHandleGetsCalled()
.Join(5)
.Join(6)
.Join(7)
.MatchSome((p1, p2, p3, p4, p5, p6, p7) => someHandleCalled = true);
.IfSome((p1, p2, p3, p4, p5, p6, p7) => someHandleCalled = true);

someHandleCalled.Should().BeTrue();
}
Expand Down
4 changes: 2 additions & 2 deletions fluentOptionals/Optionals/Optional1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void Match(Action<T1> some, Action none)
public TReturn Match<TReturn>(Func<T1, TReturn> some, Func<TReturn> none)
=> IsSome ? some(Value) : none();

public void MatchSome(Action<T1> handle) => Match(handle, () => { });
public void IfSome(Action<T1> handle) => Match(handle, () => { });

public void MatchNone(Action handle) => Match(_ => { }, handle);
public void IfNone(Action handle) => Match(_ => { }, handle);

public Optional<TMapResult> Map<TMapResult>(Func<T1, TMapResult> mapper)
=> IsSome
Expand Down
Loading

0 comments on commit 297bf87

Please sign in to comment.