public CsvResult(string fileName, IEnumerable <T> records) : this(fileName) { if (records == null) { throw new ArgumentNullException(nameof(records)); } _records = OneOf <IEnumerable <T>, IAsyncEnumerable <T> > .FromT0(records); }
public static void IsSuccess3() { var value = OneOf <int, NoElements, NoElements> .FromT0(1); int dotValue = value.Value(); // Versus the built in object regularValue = value.Value; Assert.AreEqual(1, dotValue); Assert.AreEqual(regularValue, dotValue); }
public static void RepeatedlySlideToBottomOfMap(this TobogganPosition self, Slope slope, Action <TobogganPosition> actionBetweenEachSlide) { var tobogganPosition = OneOf <TobogganPosition, BottomOfMap> .FromT0(self); do { tobogganPosition = tobogganPosition.Match(tp => tp.Slide(slope), _ => throw new InvalidOperationException()); tobogganPosition.Switch(actionBetweenEachSlide, _ => { }); }while (tobogganPosition.Match(_ => true, _ => false)); }
public static void IsSuccess3() { var value = OneOf <int, NoElements, NoElements> .FromT0(1); Assert.Throws <InvalidOperationException>( () => value.WhyNot()); Assert.Throws <InvalidOperationException>( () => { var _ = value.AsT1; }, "because parity"); }
public void AssertOption_OneOf_NotApplicableCase() { var itemToCheck = OneOf <Some <int>, None> .FromT0(new Some <int> { Value = 3 }); Action failureAction = () => itemToCheck.Should().BeCase <None>(); failureAction.Should().Throw <AssertionException>().WithMessage( "Value should be assignable to \"None\" but found \"Some<Int32>\" instead"); }
public static OneOf <IEnumerable <TResult>, TError> SelectMany <TSource, TSuccess, TError, TResult>( this IEnumerable <TSource> source, Func <TSource, OneOf <TSuccess, TError> > selector, Func <TSource, TSuccess, TResult> resultSelector) { return(source.Aggregate( OneOf <ImmutableArray <TResult>, TError> .FromT0(ImmutableArray <TResult> .Empty), (previousAggregate, currentItem) => previousAggregate.Match( previousSuccesses => selector(currentItem).Match <OneOf <ImmutableArray <TResult>, TError> >( itemSuccess => previousSuccesses.Add(resultSelector(currentItem, itemSuccess)), itemError => itemError), previousError => previousError), aggregate => aggregate.Match <OneOf <IEnumerable <TResult>, TError> >(allSuccesses => allSuccesses, error => error))); }
public void AssertOption_OneOf_CaseNotPresent() { var itemToCheck = OneOf <Some <int>, None> .FromT0( new Some <int> { Value = 3 }); Action failureAction = () => itemToCheck.Should().BeCase <int>(); failureAction.Should().Throw <AssertionException>().WithMessage( "Unable to find any Discriminated Union method on type \"OneOf<Some<Int32>,None>\" for expected type \"Int32\""); }
private async Task <Option <OneOf <PostReadModel, NotApprovedResult <PostReadModel> > > > FindApprovedPost(Expression <Func <PostEntity, bool> > predicate) { var postEntity = await CreateBasePostQuery().FirstOrDefaultAsync(predicate); if (postEntity == null) { return(Option.None <OneOf <PostReadModel, NotApprovedResult <PostReadModel> > >()); } else { var claims = await GetCreatorClaims(postEntity.CreatedBy.Id); var post = postEntity.ToReadModel(claims); var result = post.IsApproved ? OneOf <PostReadModel, NotApprovedResult <PostReadModel> > .FromT0(post) : OneOf <PostReadModel, NotApprovedResult <PostReadModel> > .FromT1(new NotApprovedResult <PostReadModel>(post)); return(Option.Some(result)); } }
public void AssertOption_OneOf_SomeFound() { //Arrange var itemToCheck = OneOf <Some <int>, None> .FromT0(new Some <int> { Value = 3 }); //Assert itemToCheck .Should() .BeCase <Some <int> >() .And .Should() .BeEquivalentTo( new Some <int> { Value = 3 }); }
public static OneOf <TobogganPosition, BottomOfMap> Slide(this TobogganPosition self, Slope slope) { var result = OneOf <TobogganPosition, BottomOfMap> .FromT0(Enumerable.Range(0, slope.right).Aggregate(self, (p, _) => p.MoveRight())); return(Enumerable.Range(0, slope.down).Aggregate(result, (p, _) => p.Match(p => p.MoveDown(), p => p))); }
public void ResolveIFooFromResultMethod() { var result = OneOf <IFoo, int> .FromT0(new Foo()); }
public static void IsSuccess3() { var value = OneOf <int, NoElements, NoElements> .FromT0(1); Assert.IsTrue(value.IsSuccess()); }