public void TestEIf()
        {
            var test1 = BF.EIf(false, () => "abc", () => 3);

            Assert.AreEqual("abc", test1.Match(left: n => n.ToString(), right: BF.Identity));
            var test2 = BF.EIf(false, () => test1, () => 19);

            Assert.AreEqual("abc", test2.Match(left: n => n.ToString(), right: BF.Identity));
            var test3 = BF.EIf(false, () => "abc", () => test1);

            Assert.AreEqual("abc", test3.Match(left: n => n.ToString(), right: BF.Identity));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Type-safe version of LINQs 'Single' and 'SingleOrDefault' function that returns a Maybe
 /// instead of possibly throwing an exception or returning null
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="items">A queryable of elements that we want the only element of</param>
 /// <returns>The only value in the queryable, or nothing if no such element exists or multiple elements exist</returns>
 public static IMaybe <T> MaybeSingle <T>(this IQueryable <T> items)
 {
     return(items.MaybeSingle(BasicFunctions.Const <T, bool>(true).AsExpression()));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Type-safe version of LINQs 'Single' and 'SingleOrDefault' function that returns a Maybe
 /// instead of possibly throwing an exception or returning null
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="items">An enumerable of elements that we want the only element of</param>
 /// <returns>The only value in the enumerable, or nothing if no such element exists or multiple elements exist</returns>
 public static IMaybe <T> MaybeSingle <T>(this IEnumerable <T> items)
 {
     return(items.MaybeSingle(BasicFunctions.Const <T, bool>(true)));
 }