GithubHelp home page GithubHelp logo

funcs's Introduction

FunCs

Functional extensions and support for C#.

What it's for

Very lightweight syntax functional support for C#, for things which either don't exist, or a pain to use.

Currently included:

  • Use var to declare lambdas;
  • Functional composition;
  • Partial function application (currying).

Use 'var' to declare lambdas:

What is a less of a pain and makes more sense to you? And what is easier to convert to a method should you want to?

// Standard C#
Func<int, string> f = (x) => x.ToString();

// With FunCs
var f = Fun.function((int x) => x.ToString());

Restrictions:

  • Can only use inside a method: can't use var to declare instance members :(
  • Up to 9 input parameters;
  • It's a Func, so must have a return value, can't do `void.

Function composition: create functions by chaining them together.

var stringToInt = Fun.function((string s) => int.Parse(s));
var intToHexString = Fun.function((int n) => n.ToString("X"));

// compose
var stringToHexString = Fun.compose(stringToInt, intToHexString);

// or, using extension
var stringToHexString = stringToInt.compose(intToHextString);

// use it
var s = stringToHexString("255");  // = "FF"

Restrictions:

  • Can only use with Func<> types.
  • Cannot use with methods :( For a somewhat unconvincing answer why, see Eric Lippert's post on SO.

Partial function application (currying)

var plus = Fun.function((int x1, int x2) => x1 + x2);
var plus10 = plus.curry(10);    // or Fun.curry(plus, 10)
var r1 = plus(2);               // = 10 + 2 = 12
var r2 = plus(5);               // = 10 + 5 = 15

Restrictions:

  • Same as with compose.

Getting the stuff

This is a sort of a "beta" at the moment. More stuff will be added.

.NET Version Support

Currently only 4.0 and 4.5.

If there is a demand for earlier versions (3.5, 3.0 and 2.0), add an issue to this project.

Nuget

There is a nuget package for it here.

Binaries

There are pre-built binaries in published directory. Feel free to grab those.

Source code

Feel free to use as a source code. It should be trivial to do so.

License

MIT license. Feel free to use either as binary releases or as source code.

funcs's People

Contributors

ppanyukov avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

funcs's Issues

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.