Giter Club home page Giter Club logo

pointfree's Introduction

Pointfree

It's that easy to make a pointfree version of ImmutableJS? could we do that for other libs, or even the standard library?

Usage:

flipClass

const { flipClass } = require('pointfree');

// flipClass yields variadic functions with the main argument last (separately)
var P = R.map(flipClass)({ String, Number });

// pointfree method, with method-calling object as the last argument:
P.String.replace(/o+/g, 'b')('foo') // 'fb'
// pointfree function, first argument provided separately last:
P.String.includes('f', 2)('food') // false
// optional arguments still work, using default values if not supplied:
P.String.includes('f')('food') // true

// built-in? libraries? any should work!
var P = R.map(flipClass)({ Array, Object, Promise, Set, Observable });

// heck, why not pick out some you like?
let { then } = P.Promise;
let thenThisThenThat = R.pipe(then(fnA), then(fnB, catcher));

curryClass

const { curryClass } = require('pointfree');

// curryClass generates curried function versions of JS functions/methods
var P = R.map(curryClass)({ String, Number });

// curried method, with method-calling object as the last argument:
P.String.replace(/o+/g)('b')('foo') // 'fb'
// curried function, first argument provided last:
let leet = P.Number.parseInt('539', 16);

// optional arguments always use default values:
P.String.includes('f')('food') // true -- optional `position`: default 0
P.String.includes('f')(2)('food') // fails, arity is 2
// explicit-arity variants enable optional arguments:
P.String.includes3('f')(2)('food') // works, false

var P = R.map(curryClass)({ Array, Object, Promise, Set, Observable });
let { then, then2 } = P.Promise;
let thenThisThenThat = R.pipe(then(fnA), then2(fnB, catcher));

curryNClass

const { curryNClass } = require('pointfree');

// curryClass generates curried versions with explicit arities
var P = R.map(curryNClass)({ String, Number });
P.String.includes(3)('f', 2, 'food'); // arity: 3
P.String.includes(3)('f')(2)('food'); // rest still curried, of course

Using on libraries, standard library

// manually picking classes too much effort? why not grab all in `window`?
const classes = R.pipe(
  Object.getOwnPropertyNames,
  R.map(k => [k, window[k]]),
  R.fromPairs,
  R.filter(c => c && c.prototype),
)(window);

// curried Array methods? check. Date? sure. Map or Promise? yep, unless you're on IE5.
var P = R.map(flipClass)(classes);

// ImmutableJS
let Immutable = require('immutable');
let { Map: IMap, Set: ISet } = Immutable;
var P = R.map(flipClass)({ IMap, ISet });

// curryClass: ditto

Context:

But... I could just write p=>p.then(f)!

Yeah. Common functions can be taken out though, like then above. Method notation may also get a bit more verbose with TypeScript/Flow typings, though type inference is still tough here as well.

pointfree's People

Contributors

kiaragrouwstra avatar

Stargazers

Philip Peterson avatar Eva1ent avatar  avatar Ye Thu avatar Jacob Chapman avatar zhangaz1 avatar Michael Joseph avatar  avatar Tim Kersey avatar Géraud Henrion avatar Josh Burgess avatar Bernhard Mayr avatar Michael Joseph Rosenthal avatar Furkan Tunalı avatar nichoth avatar Wojciech Karaś avatar Wes Moberly avatar Rob Hilgefort avatar Łukasz avatar Aki avatar Ben Jackman avatar Mick Dekkers avatar Niels Heisterkamp avatar Scott Sauyet avatar

Watchers

Scott Sauyet avatar zhangaz1 avatar  avatar Mick Dekkers avatar  avatar

Forkers

zhangaz1

pointfree's Issues

Taking over

Hey,

This looks to be no longer maintained but i like the name and would like to do something very similiar to this. Would you consider letting me take this over?

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.