sweet-ramda

0.0.2 • Public • Published

sweet-ramda : SweetJS macros for Ramda

This project aims to use the power of SweetJS macros to provide syntaxic sugar over Ramda library.

For the moment, this is an alpha release and mostly experimental.

How to get sweet-ramda macros

You can fetch it using NPM npm install sweet-ramda or directly download the sweet-ramda.sjs file from this repo.

All the macros are defined in sweet-ramda.sjs.

Requirements

To be able to use it in your project, you must have SweetJS installed. You can do it also via NPM : npm install sweet.js

How to use it with a build tool

For the moment, I only tried to use SweetJS with Gulp. To do so, you will need to install "gulp-sweetjs" module : npm install gulp-sweetjs.

For example, you can defined a building task like this :

var gulp = require('gulp'),
    sweetjs = require('gulp-sweetjs');

gulp.task('build', function () {
    return gulp.src('src/*.js')
            .pipe(sweetjs({
                modules: ['PATH_TO_SWEET_RAMDA/sweet-ramda']
            }))
            .pipe(gulp.dest('build'));
});

Macros

The number of macros is quite little for now, but it will grow and it will focus on providing syntaxic sugar over the most usefull functions of Ramda.

import_ramda

Because of SweetJS enfore hygiene, a little hack is needed to bind every macros to the Ramda library. When you want to use macros defined in sweet-ramda, you will need to use this import_ramda macro on the top of your file, like this :

import_ramda R from "ramda"

/* Use every macro you want here :) */

map

Usage : map f arr where "f" is a function and "arr" a list (see R.map )

Note : You can use also map f to create a new function, using the automatic currying of Ramda.

filter

Usage : filter pred arr where "pred" is a predicate function and "arr" a list (see R.filter )

Note : You can use also filter f to create a new function, using the automatic currying of Ramda.

compose

Usage : f .. g where "f" and "g" are functions. It will be replaced by R.compose(f, g) (see R.compose )

id

Usage : id value where "value" is a litteral (see R.identity )

Note : it will be soon extended to objects.

curry

Usage : curry f where f is a function (see R.curry )

Placeholder

Usage : _ corresponding to R.__ (see R.__ )

This is usefull combined with currying :

function minus (a, b) {
    return a - b;
}

var curriedMinus = curry minus

var minusOne = minus(_, 1)

map minusOne [1, 2, 3]

Contributing

If you find this project great but you absolutely need a macro for a specific function, or if some of the existing macros can be improved, don't hesitate to create a new issue, to make a PR or to contact me on Twitter.

Readme

Keywords

Package Sidebar

Install

npm i sweet-ramda

Weekly Downloads

7

Version

0.0.2

License

ISC

Last publish

Collaborators

  • thomasc__