All Projects → saschagrunert → Func

saschagrunert / Func

Licence: mit
Functional additions to C

Programming Languages

c
50402 projects - #5 most used programming language
cpp
1120 projects

Projects that are alternatives of or similar to Func

Ios Oss
Kickstarter for iOS. Bring new ideas to life, anywhere.
Stars: ✭ 7,840 (+13417.24%)
Mutual labels:  functional-programming
Bkmrkd
Bkmrkd is a self-hosted, lightweight bookmarking service run on node.js and rethinkdb
Stars: ✭ 52 (-10.34%)
Mutual labels:  functional-programming
Jhc Components
JHC Haskell compiler split into reusable components
Stars: ✭ 55 (-5.17%)
Mutual labels:  functional-programming
Mostly Adequate Guide Ru
Mostly adequate guide to FP (in javascript, translated to russian)
Stars: ✭ 1,030 (+1675.86%)
Mutual labels:  functional-programming
Functionalrx
FunctionalRx is a collection of constructs to simplify a functional programming approach to Java and [STABLE]
Stars: ✭ 47 (-18.97%)
Mutual labels:  functional-programming
Bullseye
A functional language frontend for the Dart VM.
Stars: ✭ 53 (-8.62%)
Mutual labels:  functional-programming
Graphql Lodash
🛠 Data manipulation for GraphQL queries with lodash syntax
Stars: ✭ 1,003 (+1629.31%)
Mutual labels:  functional-programming
Noexception
Java library for handling exceptions in concise, unified, and architecturally clean way.
Stars: ✭ 56 (-3.45%)
Mutual labels:  functional-programming
Qt Promise
Chainable promises for Qt
Stars: ✭ 48 (-17.24%)
Mutual labels:  functional-programming
Modules
Modules in R
Stars: ✭ 54 (-6.9%)
Mutual labels:  functional-programming
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (-22.41%)
Mutual labels:  functional-programming
Smallfunction
Stack allocated and type-erased functors 🐜
Stars: ✭ 47 (-18.97%)
Mutual labels:  functional-programming
Tsoption
Correct, easy to use Option type for TypeScript. 🦄
Stars: ✭ 53 (-8.62%)
Mutual labels:  functional-programming
Karate
Webscraper
Stars: ✭ 45 (-22.41%)
Mutual labels:  functional-programming
Affect
Algebraic effects for Ruby
Stars: ✭ 56 (-3.45%)
Mutual labels:  functional-programming
Osagai
🀄️A tiny library for creating WebComponents in a Functional way
Stars: ✭ 42 (-27.59%)
Mutual labels:  functional-programming
Rambda
Faster and smaller alternative to Ramda
Stars: ✭ 1,066 (+1737.93%)
Mutual labels:  functional-programming
Scodec Stream
Binding between scodec and FS2
Stars: ✭ 57 (-1.72%)
Mutual labels:  functional-programming
Haskell Book Readers Exercises
Exercises from the readers of the Haskell Book
Stars: ✭ 56 (-3.45%)
Mutual labels:  functional-programming
Seamless Immutable Cursor
Compact Cursor Library built on top of the excellent seamless-immutable
Stars: ✭ 54 (-6.9%)
Mutual labels:  functional-programming

func - Functional additions to C Build Status

Func provides - header only - functional additions to the C language. For now, the following features are included:

Installation

Simply add the include folder as a dependency to your project and include the main header file:

#include <Func.h>

Usage

Maybe

A Maybe type is a polymorphic type that represents encapsulation of an optional value.

The type can be used like this:

#include "include/Func.h"

MAYBE(int, foo);

/* Alternatively, if you dont need the 'foo' synonym:
 * MAYBE_TYPE(int); */
 
 /* Maybe will only take struct pointers */
struct bar { int value; };
MAYBE(struct bar *, bar);
/* MAYBE(struct bar, bar); */ /* ERROR */

int main(void) {
    Maybe(foo) maybeFoo = Just_foo(2);

    /* check if the Maybe value contains nothing */
    if (isNothing(maybeFoo)) {
        /* wont be executed */
    }

    /* check if the Maybe value contains something */
    if (isJust(maybeFoo)) {
        /* will be executed */
    }

    /* Extract the content to `t`.
     * Will evaluate to the default value '0'
     * if the maybeFoo would be 'Nothing' */
    int t = fromMaybe(0, maybeFoo);

    /* t will be `2` now */

    return 0;
}

Either

The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b.

The Either type is sometimes used to represent a value which is either correct or an error; by convention, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").

#include "include/Func.h"

EITHER(int, foo, char, bar);

/* Alternatively, if you dont need the 'foo' and 'bar' synonyms:
 * EITHER_TYPE(int, char); */
 
 /* Either will only take struct pointers */
struct baz { int value; };
EITHER(struct baz *, baz, char, bax);
/* EITHER(struct baz, baz, char, bax); */ /* ERROR */

int main(void) {
    Either(foo, bar) eitherFooOrBar = Right_foo_bar('a');

    if (isLeft(eitherFooOrBar)) {
        /* wont be executed */
    }

    if (isRight(eitherFooOrBar)) {
        /* will be executed */
    }

    /* Try to extract the Left content to `x`.
     * Will evaluate to the default '1' if the
     * Either type would be 'Right' */
    int x = fromLeft(1, eitherFooOrBar);

    /* x will be '1' */

    /* Try to extract the Right content to `y`.
     * Will evaluate to the default ' ' if the
     * Either type is 'Left' */
    char y = fromRight(' ', eitherFooOrBar);

    /* y will be 'a' */

    return 0;
}

Contributing

You want to contribute to this project? Wow, thanks! So please just fork it and send me a pull request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].