Last active
July 3, 2020 07:52
-
-
Save jovaneyck/33faf4459490ff013762e5997633eece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using FluentAssertions; | |
using Xunit; | |
using LanguageExt; | |
using static LanguageExt.Prelude; | |
namespace LanguageExtDemo | |
{ | |
public class Either | |
{ | |
[Fact] | |
public void mapping_a_list_of_eithers_to_an_either_of_lists() | |
{ | |
Assert.Equal( | |
Right(List(1,2,3)), | |
List((Either<string,int>)Right(1), Right(2), Right(3)).Sequence()); | |
Assert.Equal( | |
Left("error"), | |
List((Either<string,int>)Right(1), Right(2), Left("error"), Right(3)).Sequence()); | |
} | |
[Fact] | |
public void mapping_an_enumerable_of_eithers_to_an_either_of_enumerable() | |
{ | |
Either<string,List<int>> result = new List<Either<string, int>> {Right(1), Right(2), Right(3)} | |
.Aggregate( | |
(Either<string, List<int>>) Right(new List<int>()), | |
(ma, mb) => | |
from a in ma | |
from b in mb | |
select a.Concat(new []{b}).ToList()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment