public async Task WhenAllAreSome_UsingMethodReference_ReturnsSome() { const int firstValue = 23; var first = AsyncMaybe <int> .Some(firstValue); const int secondValue = 6589; var second = AsyncMaybe <int> .Some(secondValue); const int thirdValue = 236589; var third = AsyncMaybe <int> .Some(thirdValue); const int fourthValue = 1236589; var fourth = AsyncMaybe <int> .Some(fourthValue); Task <ValueTuple <int, int, int, int> > Zipper(int v1, int v2, int v3, int v4) => Task.FromResult((v1, v2, v3, v4)); var result = await first.ZipAsync(second, third, fourth, Zipper); var value = result.MustBeSome(); Assert.Equal(firstValue, value.Item1); Assert.Equal(secondValue, value.Item2); Assert.Equal(thirdValue, value.Item3); Assert.Equal(fourthValue, value.Item4); }
public async Task WhenFirstIsSome_AndSecondIsSome_AndThirdIsSome_AndFourthIsSome_UsingMethodReference_ReturnsSome() { const int firstValue = 23; var first = AsyncMaybe <int> .Some(firstValue); const int secondValue = 6589; var second = AsyncMaybe <int> .Some(secondValue); const int thirdValue = 2136589; var third = AsyncMaybe <int> .Some(thirdValue); const int fourthValue = 547894; var fourth = AsyncMaybe <int> .Some(fourthValue); ValueTuple <int, int, int, int> Zipper(int f, int s, int t, int f4) => (f, s, t, f4); var result = await first.Zip(second, third, fourth, Zipper); var value = result.MustBeSome(); Assert.Equal(firstValue, value.Item1); Assert.Equal(secondValue, value.Item2); Assert.Equal(thirdValue, value.Item3); Assert.Equal(fourthValue, value.Item4); }
public async Task Sync_WhenSome_ReturnsMappedResult() { const int expected = 5; var result = await AsyncMaybe <int> .Some(2).Map(some => some + 3).OrFail(); Assert.Equal(expected, result); }
public async Task WithLambdas() { var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some => some + 1, none => 0); Assert.Equal(2, result); }
public async Task Some() { var source = AsyncMaybe <object> .Some(1); var isSome = await source.IsSome; Assert.True(isSome); }
public async Task WithLambdas() { var source = AsyncMaybe <int> .Some(1); var result = await source.MatchAsync(some => Task.FromResult(some + 1), none => Task.FromResult(0)); Assert.Equal(2, result); }
public async Task OnNone_WithAsyncSome_ReturnsOther() { const int expected = 34; var source = await AsyncMaybe <int> .None().Or(AsyncMaybe <int> .Some(expected)); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_WithLambdaReturningAsyncSome_ReturnsSelf() { const int expected = 34; var source = await AsyncMaybe <int> .Some(expected).Or(() => AsyncMaybe <int> .Some(545)); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_WithMethodReferenceReturningAsyncNone_ReturnsSelf() { const int expected = 34; var source = await AsyncMaybe <int> .Some(expected).Or(AsyncMaybe <int> .None); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_WithAsyncSome_ReturnsSelf() { const int expected = 34; var source = await AsyncMaybe <int> .Some(expected).OrAsync(Task.FromResult(AsyncMaybe <int> .Some(545))); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task WithAsyncSomeSome_ReturnsResultOfSome() { const int expected = 3; var source = await AsyncMaybe <int> .Some(1).Map(it => AsyncMaybe <int> .Some(3)).Flatten(); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task WithSomeReference_AndNoneLambda() { Task <int> MatchSome(int some) => Task.FromResult(some + 1); var source = AsyncMaybe <int> .Some(1); var result = await source.MatchAsync(MatchSome, none => Task.FromResult(0)); Assert.Equal(2, result); }
public async Task WithSomeLambda_AndNoneReference() { Task <int> MatchNone(None none) => Task.FromResult(0); var source = AsyncMaybe <int> .Some(1); var result = await source.MatchAsync(some => Task.FromResult(some + 1), MatchNone); Assert.Equal(2, result); }
public async Task Sync_OnSome_ReturnsSameAsMap() { var source = AsyncMaybe <int> .Some(3); var where = await source.Select(it => it * 2); var map = await source.Map(it => it * 2); Assert.Equal(where, map); }
public async Task WithSomeReference_AndNoneLambda() { int MatchSome(int some) => some + 1; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some : MatchSome, none : none => 0); Assert.Equal(2, result); }
public async Task WithSomeLambda_AndNoneReference() { int MatchNone(None none) => 0; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some => some + 1, none : MatchNone); Assert.Equal(2, result); }
public async Task Async_OnSome_ReturnsSameAsMapAsync() { var source = AsyncMaybe <int> .Some(3); var where = await source.SelectAsync(it => Task.FromResult(it * 2)); var map = await source.MapAsync(it => Task.FromResult(it * 2)); Assert.Equal(where, map); }
public async Task WithReferences() { int MatchSome(int some) => some + 1; Task <int> MatchNone() => Task.FromResult(0); var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some : MatchSome, noneAsync : MatchNone); Assert.Equal(2, result); }
public async Task WhenSome_ReturnsSingleItemEnumerable() { const int expectedValue = 230023; var source = AsyncMaybe <int> .Some(expectedValue); var result = await source.ToEnumerable(); var value = Assert.Single(result); Assert.Equal(expectedValue, value); }
public async Task WithLambdas() { var some = 0; var none = 0; var source = AsyncMaybe <int> .Some(1); await source.Match(_ => { some++; return(TaskCache.CompletedTask); }, _ => { none++; return(TaskCache.CompletedTask); }); Assert.Equal(1, some); Assert.Equal(0, none); }
public async Task OnSome_WithLambdaReturningAsyncNone_ReturnsSelf() { const int expected = 34; // ReSharper disable once ConvertClosureToMethodGroup var source = await AsyncMaybe <int> .Some(expected).OrAsync(() => Task.FromResult(AsyncMaybe <int> .None())); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task WithReferences() { Task <int> MatchSome(int some) => Task.FromResult(some + 1); Task <int> MatchNone(None none) => Task.FromResult(0); var source = AsyncMaybe <int> .Some(1); var result = await source.MatchAsync(MatchSome, MatchNone); Assert.Equal(2, result); }
public async Task WithReferences() { int MatchSome(int some) => some + 1; int MatchNone(None none) => 0; var source = AsyncMaybe <int> .Some(1); var result = await source.Match(some : MatchSome, none : MatchNone); Assert.Equal(2, result); }
public async Task WhenFirstIsNone_AndSecondIsSome_UsingLambda_ReturnsNone() { var first = AsyncMaybe <int> .None(); const int secondValue = 6589; var second = AsyncMaybe <int> .Some(secondValue); var result = await first.Zip(second, (f, s) => (first : f, second : s)); result.MustBeNone(); }
public async Task WithLambdas() { var some = 0; var none = 0; var source = AsyncMaybe <int> .Some(1); await source.Match(value => { some++; }, none : () => { none++; }); Assert.Equal(1, some); Assert.Equal(0, none); }
public async Task WhenFirstIsSome_AndSecondIsNone_AndThirdIsSome_ReturnsNone() { var first = AsyncMaybe <int> .Some(451); var second = AsyncMaybe <int> .None(); var third = AsyncMaybe <int> .Some(123); var result = await first.Zip(second, third, (f, s, t) => (f, s, t)); result.MustBeNone(); }
public async Task OnNone_WithMethodReferenceReturningAsyncSome_ReturnsOther() { const int expected = 34; Task <AsyncMaybe <int> > Other() => Task.FromResult(AsyncMaybe <int> .Some(expected)); var source = await AsyncMaybe <int> .None().OrAsync(otherAsync: Other); var result = source.MustBeSome(); Assert.Equal(expected, result); }
public async Task OnSome_ReturnsSource() { const int expected = 5; var source = Maybe <int> .Some(expected); var other = AsyncMaybe <int> .Some(79); var result = await source.OrAsync(other); var value = result.MustBeSome(); Assert.Equal(expected, value); }
public async Task OnNone_WithLambda_ReturnsOther() { const int expected = 79; var source = Maybe <int> .None(); var other = AsyncMaybe <int> .Some(expected); var result = await source.OrAsync(() => other); var value = result.MustBeSome(); Assert.Equal(expected, value); }
public async Task WithSomeReference_AndNoneLambda() { var some = 0; var none = 0; void MatchSome(int value) => some++; var source = AsyncMaybe <int> .Some(1); await source.Match(some : MatchSome, none : () => { none++; }); Assert.Equal(1, some); Assert.Equal(0, none); }