View Code? Open in Web Editor
NEW
Brings additional type safety to C#, by providing an explicit replacement for nullable reference types. Also comes with functional operators, LINQ and out of the box model binding and JSON support.
License: MIT License
C# 99.34%
PowerShell 0.45%
Batchfile 0.21%
amplified.monads.maybe's People
Contributors
amplified.monads.maybe's Issues
public static IEnumerable < TResult > SelectSome < T , TResult > ( this IEnumerable < T > source , Func < T , Maybe < TResult > > selector )
{
return source. Select ( selector) . SelectMany ( item => item. ToEnumerable ( ) ) ;
}
It would be nice to have extension methods on IQueryable<T>
like on IEnumerable<T>
:
public static Maybe < T > SingleOrNone < T > ( this IQueryable < T > source ) ;
public static Maybe < T > SingleOrNone < T > ( this IQueryable < T > source , Expression < Func < T , bool > > predicate ) ;
public static Maybe < T > FirstOrNone < T > ( this IQueryable < T > source ) ;
public static Maybe < T > FirstOrNone < T > ( this IQueryable < T > source , Expression < Func < T , bool > > predicate ) ;
public static Maybe < T > LastOrNone < T > ( this IQueryable < T > source ) ;
public static Maybe < T > LastOrNone < T > ( this IQueryable < T > source , Expression < Func < T , bool > > predicate ) ;
The following extension methods are generally usable, but missing from the package:
public static T? OrNull < T > ( this Maybe < T > source ) where T : struct { }
// Collections
public static Maybe < TValue > GetValueOrNone < TKey , TValue > ( this IDictionary < TKey , TValue > source , TKey key ) ;
public static IEnumerable < T > Some < T > ( this IEnumerable < T > source ) ;
// ReactiveX-like operators
public static Maybe < T > WhenSome < T > ( this Maybe < T > source , Action < T > action ) ;
public static Maybe < T > WhenNone < T > ( this Maybe < T > source , Action < None > action ) ;
public static Maybe < T > WhenNone < T > ( this Maybe < T > source , Action action ) ;
When modelbinding the following models:
public class Attribute
{
[ Required ]
public Translation Translation { get ; }
public class Translation
{
[ Required ]
public string Id { get ; }
public Maybe < string > Name { get ; }
}
}
And submitting input without Translation.Name set, but with Translation.Id set, the field 'Name' is reported as being required.