UNPKG

6.65 kBMarkdownView Raw
1Ramda
2=============
3
4A practical functional library for Javascript programmers.
5
6[![Build Status](https://travis-ci.org/ramda/ramda.svg?branch=master)](https://travis-ci.org/ramda/ramda)
7[![npm module](https://badge.fury.io/js/ramda.svg)](https://www.npmjs.org/package/ramda)
8[![dependencies](https://david-dm.org/ramda/ramda.svg)](https://david-dm.org/ramda/ramda)
9[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/ramda/ramda?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
10
11
12Why Ramda?
13----------
14
15<img src="http://ramda.jcphillipps.com/logo/ramdaFilled_200x235.png"
16 width="170" height="190" align="right" hspace="12" />
17
18There are already several excellent libraries with a functional flavor. Typically, they are meant to be general-purpose toolkits, suitable for working in multiple paradigms. Ramda has a more focused goal. We wanted a library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.
19
20
21What's Different?
22-----------------
23
24The primary distinguishing features of Ramda are:
25
26* Ramda emphasizes a purer functional style. Immutability and side-effect free functions
27 are at the heart of its design philosophy. This can help you get the job done with simple,
28 elegant code.
29
30* Ramda functions are automatically curried. This allows you to easily build up new functions
31 from old ones simply by not supplying the final parameters.
32
33* The parameters to Ramda functions are arranged to make it convenient for currying. The data
34 to be operated on is generally supplied last.
35
36The last two points together make it very easy to build functions as sequences of simpler functions, each of which transforms the data and passes it along to the next. Ramda is designed to support this style of coding.
37
38
39
40Also see [Why Ramda?](http://fr.umio.us/why-ramda/), [Why Curry Helps](https://web.archive.org/web/20140714014530/http://hughfdjackson.com/javascript/why-curry-helps) and [Hey Underscore, You're Doing It Wrong!](https://www.youtube.com/watch?v=m3svKOdZijA&app=desktop).
41
42
43Philosophy
44----------
45Using Ramda should feel much like just using Javascript.
46It is practical, functional Javascript. We're not introducing
47lambda expressions in strings, we're not borrowing consed
48lists, we're not porting over all of the Clojure functions.
49
50Our basic data structures are plain Javascript objects, and our
51usual collections are Javascript arrays. We also keep other
52native features of Javascript, such as functions as objects
53with properties.
54
55Functional programming is in good part about immutable objects and
56side-effect free functions. While Ramda does not *enforce* this, it
57enables such style to be as frictionless as possible.
58
59We aim for an implementation both clean and elegant, but the API is king.
60We sacrifice a great deal of implementation elegance for even a slightly
61cleaner API.
62
63Last but not least, Ramda strives for performance. A reliable and quick
64implementation wins over any notions of functional purity.
65
66Installation
67------------
68
69To use with node:
70
71```bash
72$ npm install ramda
73```
74
75Then in the console:
76
77```javascript
78var R = require('ramda');
79```
80
81To use directly in the browser:
82
83```html
84<script src="path/to/yourCopyOf/ramda.js"></script>
85```
86
87or the minified version:
88
89```html
90<script src="path/to/yourCopyOf/ramda.min.js"></script>
91```
92
93or from a CDN, either cdnjs:
94
95```html
96<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.19.0/ramda.min.js"></script>
97```
98
99or one of the below links from [jsDelivr](http://jsdelivr.com):
100
101```html
102<script src="//cdn.jsdelivr.net/ramda/0.19.0/ramda.min.js"></script>
103<script src="//cdn.jsdelivr.net/ramda/0.19/ramda.min.js"></script>
104<script src="//cdn.jsdelivr.net/ramda/latest/ramda.min.js"></script>
105```
106
107(note that using `latest` is taking a significant risk that ramda API changes could break your code.)
108
109These script tags add the variable `R` on the browser's global scope.
110
111Or you can inject ramda into virtually any unsuspecting website using [the bookmarklet](BOOKMARKLET.md).
112
113### Build
114
115* on Unix-based platforms, `npm run build` updates __dist/ramda.js__ and __dist/ramda.min.js__
116* on Windows, write the output of `scripts/build --complete` to a temporary file, then rename the temporary file __dist/ramda.js__.
117
118#### Partial Builds
119
120It is possible to build Ramda with a subset of the functionality to reduce its file size. Ramda's build system supports this with command line flags. For example if you're using `R.compose`, `R.reduce`, and `R.filter` you can create a partial build with:
121
122 ./scripts/build -- src/compose.js src/reduce.js src/filter.js > dist/ramda.custom.js
123
124This requires having Node/io.js installed.
125
126Documentation
127-------------
128
129Please review the [API documentation](http://ramdajs.com/docs/).
130
131
132
133Introductions
134-------------
135
136* [Introducing Ramda](http://buzzdecafe.github.io/code/2014/05/16/introducing-ramda/) by Buzz de Cafe
137* [Why Ramda?](http://fr.umio.us/why-ramda/) by Scott Sauyet
138* [Favoring Curry](http://fr.umio.us/favoring-curry/) by Scott Sauyet
139
140
141
142The Name
143--------
144
145Ok, so we like sheep. That's all. It's a short name, not already
146taken. It could as easily have been `eweda`, but then we would be
147forced to say _eweda lamb!_, and no one wants that. For non-English
148speakers, lambs are baby sheep, ewes are female sheep, and rams are male
149sheep. So perhaps ramda is a grown-up lambda... but probably not.
150
151
152
153
154Running The Test Suite
155----------------------
156
157**Console:**
158
159To run the test suite from the console, you need to have `mocha` installed:
160
161 npm install -g mocha
162
163Then from the root of the project, you can just call
164
165 mocha
166
167Alternately, if you've installed the dependencies, via:
168
169 npm install
170
171then you can run the tests (and get detailed output) by running:
172
173 npm test
174
175**Browser:**
176
177To run the test suite in the browser, you can simply open `test/index.html`.
178
179Alternatively, you can use [testem](https://github.com/airportyh/testem) to
180test across different browsers (or even headlessly), with livereloading of
181tests too. Install testem (`npm install -g testem`) and run `testem`. Open the
182link provided in your browser and you will see the results in your terminal.
183
184If you have _PhantomJS_ installed, you can run `testem -l phantomjs` to run the
185tests completely headlessly.
186
187
188
189
190Acknowledgements
191-----------------
192
193Thanks to [J. C. Phillipps](http://www.jcphillipps.com) for the Ramda logo.
194Ramda logo artwork &copy; 2014 J. C. Phillipps. Licensed Creative Commons
195[CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/).