Giter Club home page Giter Club logo

spicytaco.maybe's Introduction

SpicyTaco.Maybe Build status NuGet Prerelease Version MIT License

๐Ÿšจ No longer maintained. ๐Ÿšจ

Bad news. I have moved on to an entirely different platform (iOS/Swift) and will no longer be maintaining this library.

The good news is that Microsoft is introducing nullable reference types in C# 8. That should make libraries like this one less important. Although, I believe that they still have a place.

Introduction

No one likes NullReferenceExceptions. Let's change things. Let consumers of your code know when a return value might be empty. Force them to acknowledge a possible lack of value.

My goal is to make Maybe as easy to use as possible, but also force the consuming code down the path of success. I'm doing this by not including nice to have features such as implicit conversions, .HasValue or .Value, etc.

Usage

When you're returning a value that might be null, follow this style:

public Maybe<Person> GetPersonByName(string firstName, string lastName)
{
  var person = _database.People
    .Where(x => x.FirstName == firstName && x.LastName == lastName)
    .FirstOrDefault()
    .ToMaybe();
  return person;
}

You're consumer will only be able to execute code on the value through accessor methods:

GetPersonByName("John", "Doe")
  .Do(person => SomeUsefulAction(person))
  .DoWhenEmpty(() => this.Log().Warn("No user named 'John Doe' could be found."));

Install

You're welcome to install this library, but keep in mind it is a pre-release. I'm still plying with the API surface. Things might get renamed or dissapeared.

Install-Package SpicyTaco.Maybe -Pre

License

I've licensed this under MIT License. That means do what you want with this code.

spicytaco.maybe's People

Contributors

kmcginnes avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spicytaco.maybe's Issues

Using Maybe in c#8.

c# 8 is considering reference type isn't null by default and now there are two different ways for handling null reference types: Maybe and c#8.
What's the recommendation of using Maybe in c# 8.
Is there a plan for porting the library to be compiled with c# 8 support.

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.