Skip to content
/ Funcy Public

This is the insignificant one of the numberless functional libraries for C#/VB.

License

Notifications You must be signed in to change notification settings

Gab-km/Funcy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Funcy

Funcy is one of the functional libraries for C#/VB.

Usage

C#:

using System;
using Funcy;
using Funcy.Patterns;
using Funcy.Future;

namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {
            // This is the classical style.
            var maybe = Maybe<string>.Some("Hello").ComputeWith(hello =>
                Maybe<string>.Some("World").Compute(world =>
                    hello + " " + world + "!"
                )
            );
            Matcher.Match(maybe).With(
                Case<string>.From<Some<string>>().Then(s => Console.WriteLine(s)),
                Case<string>.Else().Then(() => Console.WriteLine("Fmm... Are there any troubles?"))
            );

            // This is the newer style.
            var either = EitherTC<Exception>.Right("Thank").ComputeWith(thank =>
                EitherTC<Exception>.Right("you").Compute(you =>
                    thank + " " + you + "!"
                )
            );
            Matcher.Match(either).With(
                Case<string>.From<Right<Exception, string>>().Then(s => Console.WriteLine(s)),
                Case<string>.Else().Then(() => Console.WriteLine("Fmm... Are there any troubles?"))
            );
        }
    }
}

VB:

Imports Funcy
Imports Funcy.Patterns
Imports Funcy.Future

Module Module1

    Sub Main()
        ' This is the classical style.
        Dim maybeHello = Maybe(Of String).Some("Hello").ComputeWith(
            Function(hello) Maybe(Of String).Some("World").Compute(
                Function(world) hello + " " + world + "!"
            )
        )
        Matcher.Match(maybeHello).With(
            [Case](Of String).From(Of Some(Of String))().Then(Sub(s) Console.WriteLine(s)),
            [Case](Of String).Else().Then(Sub() Console.WriteLine("Fmm... Are there any troubles?"))
        )

        ' This is the newer style.
        Dim eitherThankYou = EitherTC(Of Exception).Right("Thank").ComputeWith(
            Function(thank) EitherTC(Of Exception).Rigt("you").Compute(
                Function(you) thank + " " + you + "!"
            )
        )
        Matcher.Match(eitherThankYou).With(
            [Case](Of String).From(Of Right(Of Exception, String))().Then(Sub(s) Console.WriteLine(s)),
            [Case](Of String).Else().Then(Sub() Console.WriteLine("Fmm... Are there any troubles?"))
        )
    End Sub

End Module

Documentation

Contribution

Pull Requests are very welcome! You can also open issues freely. The one and only important point is Funcy's tests, which are written in F# and use Persimmon. Try it and familiarize yourself with it!

Build status

License

The MIT License - see LICENSE

About

This is the insignificant one of the numberless functional libraries for C#/VB.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •