1.3.5 • Published 5 years ago

ramdafier v1.3.5

Weekly downloads
2
License
ISC
Repository
-
Last release
5 years ago

Ramdafier

We love Ramda but sometimes it is painful to use R. everytime or updating the functions to import. Ramdafier helps you to import those functions in a single command. Ramdafier also includes few helpful tools to help you write in functional style such as auto curry all non-unary arrow functions, list comprehensions and range.

Execute

Execute command will rewrite your file and auto import Ramda functions that being used in the file.

$ ramdafier execute <filename>

It will write the functions on top of your files.

Watch

Auto imports all the Ramda functions being used into a new file instead of rewriting in the original file. Code will be preserved in rf.js file

$ ramdafier watch <filename>

All the updates will be done as the file saved.

Compile

Same as execute command but instead of rewrite your file it will create a new rf.js file to preserve your code.

$ ramdafier compile <filename>

New Features

This new features might help you to write less in declarative way. It transpiles Ramdafier syntax into valid javascript. List comprehensions and range functions need to be encapsulated in double quotation(""). All non-unary arrow functios will be auto-currried.

  • List Comprehension
  • Auto curry
  • Range function

List Comprehension

const list = "[x | x <- [1..10], x % 2 === 0]"; //before transpile

//after
const list = (function(mapFn, initial, last, filterFn){
    const firstArr = [];
    for(let i = initial; i <= last; i++){
      firstArr.push(i);
    }
    const secArr = firstArr.filter(filterFn);
    return secArr.map(mapFn);
  })(function anonymous(x
) {
return x
}, 1, 10, function anonymous(x
) {
return x % 2 === 0
})

Syntax

"[transformer | range, filter]"

Transformer will map the function over ranged list. Range creates an array with specified range. Filter is used to filter the elements in selected range.

note: The syntax is written within double quote without spaces

Auto curry

Auto curry helps you to curry all of your arrow functions

//before
const adder = (x, y, z) => {
    return x + y + z;
}
adder(10, 10, 10) // 30
adder(10)(10)(10) //Throws TypeError: adder(...) is not a function

//after
const adder_λ = (x, y, z) => {
  return x + y + z;
}
const adder = curry(adder_λ);
adder(10,10,10); //30
adder(10)(10)(10); //30
adder(10, 10)(10); //30
adder(10)(10, 10); //30

Range

Simple range function without needing to import any function from any library.

//before
const list = "[1..10]";

//result
const list = (function(min, max, step = 1){
    const tempArr =[];
    for(let i = min; i <= max; i += step){
      tempArr.push(i);
    }
    return tempArr;
  })(1, 10, 1)

Syntax

"[min..max]"

min and max are both inclusive

In Visual Studio Code, using ramdafier with auto-save on delay is not recommended. Others, works just fine.

1.3.5

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.4

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago