Example #1
0
        public void TestGenericNullRefConverter()
        {
            var converter = new GenericOptionJsonConverter(typeof(Maybe <>));

            Assert.True(converter.CanConvert(Maybes.None.GetType()));
            TestOptionsConverter(converter, Maybes.Some(Boxed.Of(42)));
        }
Example #2
0
 /// <summary>
 /// Tries to get a value out of a dictionary of reference types by its key, returns None maybe if it fails.
 /// </summary>
 /// <typeparam name="TK">Type of the key of the dictionary.</typeparam>
 /// <typeparam name="TV">Type of the value of the dictionary.</typeparam>
 /// <param name="dict">The dictionary to look through.</param>
 /// <param name="key">The key to look for.</param>
 /// <returns>A maybe of the dictionary's value type.</returns>
 public static Maybe <TV> GetMaybe <TK, TV>(this IReadOnlyDictionary <TK, TV> dict, TK key)
     where TV : class =>
 dict.TryGetValue(key, out var value) ? Maybes.Some(value) : Maybes.None;
Example #3
0
 public void Test_FirstMaybeWithPredicate_NotEmpty_Some()
 {
     Assert.IsTrue(Maybes.Some <object>(new object()).FirstMaybe(_ => true).HasValue);
 }
Example #4
0
 public void Test_FirstMaybe_NotEmpty_Some()
 {
     Assert.IsTrue(Maybes.Some <object>(new object()).FirstMaybe().HasValue);
 }
Example #5
0
 public void Test_FirstMaybeWithFalsePredicate_NotEmpty_None()
 {
     Assert.IsFalse(Maybes.Some <object>(new object()).FirstMaybe(_ => false).HasValue);
 }