Coder Social home page Coder Social logo

nillerr / amplified.monads.maybe Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 90 KB

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

nillerr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

amplified.monads.maybe's Issues

SelectSome

public static IEnumerable<TResult> SelectSome<T, TResult>(this IEnumerable<T> source, Func<T, Maybe<TResult>> selector)
{
    return source.Select(selector).SelectMany(item => item.ToEnumerable());
}

Queryable Extensions

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);

Missing extensions

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);

TypeConverter maybe not work correctly in MVC models

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.