Giter Site home page Giter Site logo

tp.core.functional's Introduction

Tp.Core.Functional

Tp.Core.Functional contains implementations of Maybe monad, Try monad and Either type.

Note for Github users

Primary source-of-truth repository is hosted on internal GitLab. Github repository is a read-only mirror.

Maybe monad

Maybe monad is an implementation of Option type. It represents encapsulation of an optional value; e.g. it is used as the return type of functions which may or may not return a meaningful value when they are applied.

Usages:

var i = Maybe.Just(1); // Create a value
var m = i.Select(x=>x*2); // map value, result is Just(2)
var f = m.Where(x=>x%2==1); // filter value, result is Nothing
var n = m.Bind(x=>Maybe.Just(2*x)) // flatMap (or bind) value, result is Just(4)

Tp.Functional.Core does not require to specify a type of Maybe.Nothing:

Maybe<int> n = Maybe.Nothing;
Maybe<int> m = Maybe<int>.Nothing;
n == m; // True

See more here

Either type

Either type represents disjoint union of two values:

var left = Either.CreateLeft<int,string>(1);
var right = Either.CreateRight<int,string>("string");

See more here

Try monad

A Try wraps a computation that could either result in a value or in an exception being thrown:

var tryResult = Try.Create(()=>int.Parse(value));

var m = try.Select(x=>x*2);

See more here

tp.core.functional's People

Contributors

alex-fomin avatar alexsane avatar khmylov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tp.core.functional's Issues

FromTryOut to delegate

Func<string, Maybe<int>> maybeParse = Maybe.FromTryOut(int.TryParse);
Maybe<int> v = maybeParse("2");

Builds and tests on Mono

Would be nice to add another CI step with building and running tests on Mono. Some good .NET OS libraries already do that, so the infrastructure should not be a problem here.

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.