UNPKG

6.72 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
39Introductions
40-------------
41
42* [Introducing Ramda](http://buzzdecafe.github.io/code/2014/05/16/introducing-ramda) by Buzz de Cafe
43* [Why Ramda?](http://fr.umio.us/why-ramda/) by Scott Sauyet
44* [Favoring Curry](http://fr.umio.us/favoring-curry/) by Scott Sauyet
45* [Why Curry Helps](https://hughfdjackson.com/javascript/why-curry-helps/) by Hugh Jackson
46* [Hey Underscore, You're Doing It Wrong!](https://www.youtube.com/watch?v=m3svKOdZijA&app=desktop) by Brian Lonsdorf
47* [Thinking in Ramda](http://randycoulman.com/blog/categories/thinking-in-ramda) by Randy Coulman
48
49
50Philosophy
51----------
52Using Ramda should feel much like just using JavaScript.
53It is practical, functional JavaScript. We're not introducing
54lambda expressions in strings, we're not borrowing consed
55lists, we're not porting over all of the Clojure functions.
56
57Our basic data structures are plain JavaScript objects, and our
58usual collections are JavaScript arrays. We also keep other
59native features of JavaScript, such as functions as objects
60with properties.
61
62Functional programming is in good part about immutable objects and
63side-effect free functions. While Ramda does not *enforce* this, it
64enables such style to be as frictionless as possible.
65
66We aim for an implementation both clean and elegant, but the API is king.
67We sacrifice a great deal of implementation elegance for even a slightly
68cleaner API.
69
70Last but not least, Ramda strives for performance. A reliable and quick
71implementation wins over any notions of functional purity.
72
73Installation
74------------
75
76To use with node:
77
78```bash
79$ npm install ramda
80```
81
82Then in the console:
83
84```javascript
85var R = require('ramda');
86```
87
88To use directly in the browser:
89
90```html
91<script src="path/to/yourCopyOf/ramda.js"></script>
92```
93
94or the minified version:
95
96```html
97<script src="path/to/yourCopyOf/ramda.min.js"></script>
98```
99
100or from a CDN, either cdnjs:
101
102```html
103<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.23.0/ramda.min.js"></script>
104```
105
106or one of the below links from [jsDelivr](http://jsdelivr.com):
107
108```html
109<script src="//cdn.jsdelivr.net/ramda/0.23.0/ramda.min.js"></script>
110<script src="//cdn.jsdelivr.net/ramda/0.23/ramda.min.js"></script>
111<script src="//cdn.jsdelivr.net/ramda/latest/ramda.min.js"></script>
112```
113
114(note that using `latest` is taking a significant risk that ramda API changes could break your code.)
115
116These script tags add the variable `R` on the browser's global scope.
117
118Or you can inject ramda into virtually any unsuspecting website using [the bookmarklet](https://github.com/ramda/ramda/blob/master/BOOKMARKLET.md).
119
120### Build
121
122* on Unix-based platforms, `npm run build` updates __dist/ramda.js__ and __dist/ramda.min.js__
123* on Windows, write the output of `scripts/build --complete` to a temporary file, then rename the temporary file __dist/ramda.js__.
124
125#### Partial Builds
126
127It 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:
128
129 ./scripts/build -- src/compose.js src/reduce.js src/filter.js > dist/ramda.custom.js
130
131This requires having Node/io.js installed.
132
133Documentation
134-------------
135
136Please review the [API documentation](http://ramdajs.com/docs/).
137
138The Name
139--------
140
141Ok, so we like sheep. That's all. It's a short name, not already
142taken. It could as easily have been `eweda`, but then we would be
143forced to say _eweda lamb!_, and no one wants that. For non-English
144speakers, lambs are baby sheep, ewes are female sheep, and rams are male
145sheep. So perhaps ramda is a grown-up lambda... but probably not.
146
147
148
149
150Running The Test Suite
151----------------------
152
153**Console:**
154
155To run the test suite from the console, you need to have `mocha` installed:
156
157 npm install -g mocha
158
159Then from the root of the project, you can just call
160
161 mocha
162
163Alternately, if you've installed the dependencies, via:
164
165 npm install
166
167then you can run the tests (and get detailed output) by running:
168
169 npm test
170
171**Browser:**
172
173To run the test suite in the browser, you can simply open `test/index.html`.
174
175Alternatively, you can use [testem](https://github.com/airportyh/testem) to
176test across different browsers (or even headlessly), with livereloading of
177tests too. Install testem (`npm install -g testem`) and run `testem`. Open the
178link provided in your browser and you will see the results in your terminal.
179
180If you have _PhantomJS_ installed, you can run `testem -l phantomjs` to run the
181tests completely headlessly.
182
183
184
185
186Acknowledgements
187-----------------
188
189Thanks to [J. C. Phillipps](http://www.jcphillipps.com) for the Ramda logo.
190Ramda logo artwork &copy; 2014 J. C. Phillipps. Licensed Creative Commons
191[CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/).