1 | Ramda
|
2 | =============
|
3 |
|
4 | A 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 |
|
12 | Why Ramda?
|
13 | ----------
|
14 |
|
15 | <img src="http://ramda.jcphillipps.com/logo/ramdaFilled_200x235.png"
|
16 | width="170" height="190" align="right" hspace="12" />
|
17 |
|
18 | There 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 |
|
21 | What's Different?
|
22 | -----------------
|
23 |
|
24 | The 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 |
|
36 | The 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 |
|
40 | Also 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 |
|
43 | Philosophy
|
44 | ----------
|
45 | Using Ramda should feel much like just using Javascript.
|
46 | It is practical, functional Javascript. We're not introducing
|
47 | lambda expressions in strings, we're not borrowing consed
|
48 | lists, we're not porting over all of the Clojure functions.
|
49 |
|
50 | Our basic data structures are plain Javascript objects, and our
|
51 | usual collections are Javascript arrays. We also keep other
|
52 | native features of Javascript, such as functions as objects
|
53 | with properties.
|
54 |
|
55 | Functional programming is in good part about immutable objects and
|
56 | side-effect free functions. While Ramda does not *enforce* this, it
|
57 | enables such style to be as frictionless as possible.
|
58 |
|
59 | We aim for an implementation both clean and elegant, but the API is king.
|
60 | We sacrifice a great deal of implementation elegance for even a slightly
|
61 | cleaner API.
|
62 |
|
63 | Last but not least, Ramda strives for performance. A reliable and quick
|
64 | implementation wins over any notions of functional purity.
|
65 |
|
66 | Installation
|
67 | ------------
|
68 |
|
69 | To use with node:
|
70 |
|
71 | ```bash
|
72 | $ npm install ramda
|
73 | ```
|
74 |
|
75 | Then in the console:
|
76 |
|
77 | ```javascript
|
78 | var R = require('ramda');
|
79 | ```
|
80 |
|
81 | To use directly in the browser:
|
82 |
|
83 | ```html
|
84 | <script src="path/to/yourCopyOf/ramda.js"></script>
|
85 | ```
|
86 |
|
87 | or the minified version:
|
88 |
|
89 | ```html
|
90 | <script src="path/to/yourCopyOf/ramda.min.js"></script>
|
91 | ```
|
92 |
|
93 | or from a CDN, either cdnjs:
|
94 |
|
95 | ```html
|
96 | <script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.18.0/ramda.min.js"></script>
|
97 | ```
|
98 |
|
99 | or one of the below links from [jsDelivr](http://jsdelivr.com):
|
100 |
|
101 | ```html
|
102 | <script src="//cdn.jsdelivr.net/ramda/0.18.0/ramda.min.js"></script>
|
103 | <script src="//cdn.jsdelivr.net/ramda/0.18/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 |
|
109 | These script tags add the variable `R` on the browser's global scope.
|
110 |
|
111 | Or 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 |
|
120 | It 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 |
|
124 | This requires having Node/io.js installed.
|
125 |
|
126 | Documentation
|
127 | -------------
|
128 |
|
129 | Please review the [API documentation](http://ramdajs.com/docs/).
|
130 |
|
131 |
|
132 |
|
133 | Introductions
|
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 |
|
142 | The Name
|
143 | --------
|
144 |
|
145 | Ok, so we like sheep. That's all. It's a short name, not already
|
146 | taken. It could as easily have been `eweda`, but then we would be
|
147 | forced to say _eweda lamb!_, and no one wants that. For non-English
|
148 | speakers, lambs are baby sheep, ewes are female sheep, and rams are male
|
149 | sheep. So perhaps ramda is a grown-up lambda... but probably not.
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | Running The Test Suite
|
155 | ----------------------
|
156 |
|
157 | **Console:**
|
158 |
|
159 | To run the test suite from the console, you need to have `mocha` installed:
|
160 |
|
161 | npm install -g mocha
|
162 |
|
163 | Then from the root of the project, you can just call
|
164 |
|
165 | mocha
|
166 |
|
167 | Alternately, if you've installed the dependencies, via:
|
168 |
|
169 | npm install
|
170 |
|
171 | then you can run the tests (and get detailed output) by running:
|
172 |
|
173 | npm test
|
174 |
|
175 | **Browser:**
|
176 |
|
177 | To run the test suite in the browser, you can simply open `test/index.html`.
|
178 |
|
179 | Alternatively, you can use [testem](https://github.com/airportyh/testem) to
|
180 | test across different browsers (or even headlessly), with livereloading of
|
181 | tests too. Install testem (`npm install -g testem`) and run `testem`. Open the
|
182 | link provided in your browser and you will see the results in your terminal.
|
183 |
|
184 | If you have _PhantomJS_ installed, you can run `testem -l phantomjs` to run the
|
185 | tests completely headlessly.
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | Acknowledgements
|
191 | -----------------
|
192 |
|
193 | Thanks to [J. C. Phillipps](http://www.jcphillipps.com) for the Ramda logo.
|
194 | Ramda logo artwork © 2014 J. C. Phillipps. Licensed Creative Commons
|
195 | [CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/).
|