GithubHelp home page GithubHelp logo

f.js's Introduction

f.js – A functional ECMAScript Library

Function Signatures

See docs/Function-Signatures.md

Functions

Table of contents


f.done

Description

Returns firstArgument.

Signature

f.done = Fn(firstArgument: Generic) -> Generic;

f.tee

Description

Returns a function that;

  • Applies args to callbacks.
  • Returns args as a List.
  • Ignores the results from callbacks.

Signature

f.tee = Fn(
    callbacks: ...Fn(args: ...Generic) -> Generic = [function(){}],
) -> Fn(args: ...Generic) -> List;

f.List.map

Description

Returns a function that;

  • Maps input to iterator then passes the the result to callback.
  • Returns the result from callback.

Signature

f.List.map = Fn(
    iterator: Fn(
        element: Generic,
        index: Int,
        array: List,
    ) -> Generic,
    callback: Fn(output: List) -> Generic = f.done,
) -> Fn(input: List) -> Generic;

Example

var addOne = function(n) { return n + 1 };
var double = function(n) { return n * 2 };

var addOneEach = f.List.map(addOne);
addOneEach([1, 2, 3]); // [2, 3, 4]

var doubleEach = f.List.map(double);
doubleEach([1, 2, 3]); // [1, 4, 6]

var addOneThenDoubleEach = f.List.map(addOne, f.List.map(double));
addOneThenDoubleEach([1, 2, 3]); // [4, 6, 8]

f.List.reduce

Description

Returns a function that;

  • Reduces input through iterator then passes the the result to callback.
  • Returns the result from callback.

Signature

f.List.reduce = Fn(
    iterator: Fn(
        previousValue: Generic,
        currentValue: Generic,
        index: Int,
        array: List,
    ) -> Generic,
    firstValue: Generic = null,
    callback: Fn(output: List) -> Generic = f.done,
) -> Fn(input: List) -> Generic;

f.Object.filterProperties

Description

Returns a function that;

  • Deletes properties from input then passes the result to callback.
  • Returns the result from callback.

Signature

f.Object.filterProperties = Fn(
    properties: ...String,
    callback: Fn(output: Object) -> Generic = f.done,
) -> Fn(input: Object) -> Generic;

Example

var removeSensitiveFields = f.Object.filterProperties('password', 'isAdmin');
Object.keys(removeSensitiveFields({
    id: 1,
    username: 'Elijah',
    password: '$2y$10$bpI4uLZfRG39MLVuWexVvuzWK2kXI1FEmFrgVVZn1FMwxeYMQoEE2',
    isAdmin: true,
    createdAt: 1422409318922,
    updatedAt: 1422409318922,
})); // ['id', 'username', 'createdAt', 'updatedAt']
Express.js + Knex.js example (http://expressjs.com/, http://knexjs.org/)
app.route('/api/users').get(function(request, response) {
    knex('Users').select().then(
        f.List.map(
            f.Object.filterProperties('password', 'isAdmin'),
            response.json
        )
    );
});

f.js's People

Contributors

ekytr avatar

Watchers

 avatar

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.