GithubHelp home page GithubHelp logo

repl's Introduction

Ramda

A practical functional library for JavaScript programmers.

Build Status npm module deno land nest badge Gitter

Why Ramda?

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.

What's Different?

The primary distinguishing features of Ramda are:

  • Ramda emphasizes a purer functional style. Immutability and side-effect free functions are at the heart of its design philosophy. This can help you get the job done with simple, elegant code.

  • Ramda functions are automatically curried. This allows you to easily build up new functions from old ones simply by not supplying the final parameters.

  • The parameters to Ramda functions are arranged to make it convenient for currying. The data to be operated on is generally supplied last.

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.

Introductions

Philosophy

Using Ramda should feel much like just using JavaScript. It is practical, functional JavaScript. We're not introducing lambda expressions in strings, we're not borrowing consed lists, we're not porting over all of the Clojure functions.

Our basic data structures are plain JavaScript objects, and our usual collections are JavaScript arrays. We also keep other native features of JavaScript, such as functions as objects with properties.

Functional programming is in good part about immutable objects and side-effect free functions. While Ramda does not enforce this, it enables such style to be as frictionless as possible.

We aim for an implementation both clean and elegant, but the API is king. We sacrifice a great deal of implementation elegance for even a slightly cleaner API.

Last but not least, Ramda strives for performance. A reliable and quick implementation wins over any notions of functional purity.

Installation

To use with node:

$ npm install ramda

Then in the console:

const R = require('ramda');

To use directly in Deno:

import * as R from "https://deno.land/x/[email protected]/mod.ts";

or using Nest.land:

import * as R from "https://x.nest.land/[email protected]/mod.ts";

To use directly in the browser:

<script src="path/to/yourCopyOf/ramda.js"></script>

or the minified version:

<script src="path/to/yourCopyOf/ramda.min.js"></script>

or from a CDN, either cdnjs:

<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.30.0/ramda.min.js"></script>

or one of the below links from jsDelivr:

<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/ramda.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/ramda@latest/dist/ramda.min.js"></script>

(note that using latest is taking a significant risk that ramda API changes could break your code.)

These script tags add the variable R on the browser's global scope.

Or you can inject ramda into virtually any unsuspecting website using the bookmarklet.

Note for versions > 0.25 Ramda versions > 0.25 don't have a default export. So instead of import R from 'ramda';, one has to use import * as R from 'ramda'; Or better yet, import only the required functions via import { functionName } from 'ramda';

Note for ES6 module and browsers In order to access to the ES6 module in browsers, one has to provide the content of the es directory (see below for the build instructions) and use import * as R from './node_modules/ramda/es/index.js';

Build

npm run build creates es, src directories and updates both dist/ramda.js and dist/ramda.min.js

Partial Builds

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:

npm run --silent partial-build compose reduce filter > dist/ramda.custom.js

This requires having Node/io.js installed and ramda's dependencies installed (just use npm install before running partial build).

Documentation

Please review the API documentation.

Also available is our Cookbook of functions built from Ramda that you may find useful.

The Name

Ok, so we like sheep. That's all. It's a short name, not already taken. It could as easily have been eweda, but then we would be forced to say eweda lamb!, and no one wants that. For non-English speakers, lambs are baby sheep, ewes are female sheep, and rams are male sheep. So perhaps ramda is a grown-up lambda... but probably not.

Running The Test Suite

Console:

To run the test suite from the console, you need to have mocha installed:

npm install -g mocha

Then from the root of the project, you can just call

mocha

Alternately, if you've installed the dependencies, via:

npm install

then you can run the tests (and get detailed output) by running:

npm test

Browser:

You can use testem to test across different browsers (or even headlessly), with livereloading of tests. Install testem (npm install -g testem) and run testem. Open the link provided in your browser and you will see the results in your terminal.

If you have PhantomJS installed, you can run testem -l phantomjs to run the tests completely headlessly.

Usage

For v0.25 and up, import the whole library or pick ES modules directly from the library:

import * as R from 'ramda'

const {identity} = R
R.map(identity, [1, 2, 3])

Destructuring imports from ramda does not necessarily prevent importing the entire library. You can manually cherry-pick methods like the following, which would only grab the parts necessary for identity to work:

import identity from 'ramda/src/identity'

identity()

Manually cherry picking methods is cumbersome, however. Most bundlers like Webpack and Rollup offer tree-shaking as a way to drop unused Ramda code and reduce bundle size, but their performance varies, discussed here. Here is a summary of the optimal setup based on what technology you are using:

  1. Webpack + Babel - use babel-plugin-ramda to automatically cherry pick methods. Discussion here, example here
  2. Webpack only - use UglifyJS plugin for treeshaking along with the ModuleConcatenationPlugin. Discussion here, with an example setup here
  3. Rollup - does a fine job properly treeshaking, no special work needed; example here

Typings

Translations

Funding

If you wish to donate to Ramda please see our Open Collective page. Thank you!

Acknowledgements

Thanks to J. C. Phillipps for the Ramda logo. Ramda logo artwork © 2014 J. C. Phillipps. Licensed Creative Commons CC BY-NC-SA 3.0.

repl's People

Contributors

buzzdecafe avatar craigdallimore avatar crosseye avatar dependabot[bot] avatar direlines avatar mattms avatar prateek951 avatar seanpoulter avatar zehua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

repl's Issues

Make the REPL destroyable

At the moment instantiating a REPL is a one-way street - it sets up event listeners and modifies the DOM without any concern for how it can put everything back how it was.

I'd quite like to be able to do something like

// Set it up
var destroy = ramdaRepl(target, config);

// Tear it down
destroy();

This would be a part of making it a good citizen on the docs page.

For bonus points, set up should detect if the desired scripts (ramda-fantasy et all) are already present and will not load them twice.

Build Help

Hey folks, I'm having trouble figuring out how to deploy the REPL to the Ramda documentation page. There were some recent temporary changes to avoid calling wzrd.in in the REPL. But they didn't deploy properly. But I'm not sure exactly what I should have done, so it's almost certainly user error.

Has anyone done it recently or have any suggestions?

I'm honestly not even sure of the current relationship between https://github.com/ramda/ramda.github.io and https://github.com/ramda/repl. Is the former supposed to be generated by the latter?

@buzzdecafe @craigdallimore @MattMS

Unexpected behaviour when logging out 'undefined'

Steps to reproduce

  1. Go the the repl
  2. Enter this: const z = [null, undefined]
  3. console.log(z)

Expected result

You should see [null, undefined] in the right-hand side

Actual result

You see [null, null]

Browser: Chrome 59.0.3071.115
OS: OSX 10.12.5 (Sierra)

Kinda strange; I'm mostly just curious if others have seen this issue.

Development mode

If I load index.html in my browser from the filesystem it fails to load the following links:

file://wzrd.in/standalone/sanctuary@latest
file://wzrd.in/standalone/ramda-fantasy@latest

and as a consequence a sanctuary is not defined error occurs.

To help with development, I'd like to

  • add http-server as per ramda.github.io
  • add a npm run dev command for watching and re-bundling as files change
  • add instructions for the above to the README.md

Embedding ramda/repl

I am working on a small React/Redux Next.js app to teach FP and React in an FP style (using Ramda). It would be very helpful to be able to embed the Ramda REPL into the app pages similarly to the way it is embedded in the Ramda documentation.

Is this permitted? If so, are there examples? The instructions here are great but inject directly into the DOM. This is complicated when working with a virtual DOM implementation such as that in React. It would be nice to have a reusable React component that provided REPL functionality and could be used multiple times on a page. If I wrote such a component, I'd be happy to share it via npm/GitHub. Or maybe one already exists?

Any help greatly appreciated.

Possibility of replacing code mirror with Monaco editor

It would be awesome if we could explore the possibility of using Monaco editor instead of code mirror since it comes with intellisense and some of the default editor features ( commenting, auto-complete, code-folding )

Consider moving index.html into test folder

Since the current index.html seems to be used for testing, maybe it should be moved into the test folder to avoid confusion.

This may also require updating the server npm script.

Steps to take to make this the "Try Ramda" repl

At present there are two versions of the ramda repl being maintained as far as I can tell - this one, and the one at ramda.github.io. I presume we want this one to take over from that one.

Does anyone have particular thoughts/recommendations on how that should be arranged? Perhaps we just add in a link to the bundle.js in this repo and instantiate an instance?

Draggable split

It might be nice to be able to resize the panels by dragging the central split rather than having it locked at halfway (when the split is vertical).

Enhancement - Improve "Duplicate declaration" message for Ramda fns

When a user declares a variable with the same name as one of Ramda's exports they get an error message that says ramda: Duplicate declaration "<fn>". For users who are new to Ramda, it is not immediately obvious that there's a conflict with one of Ramda's exports.

Proposal

Can we change the wording to say something like:

ramda: Cannot declare "<fn>" that conflicts with "<fn>" already imported from Ramda

If that sounds good, I'm happy to try a PR. Any tips on where to look in the code?

Steps to Reproduce

REPL link: https://goo.gl/68HEdc

CC @judyc

Expose / remove the examples

Perhaps I'm missing something obvious, but I cannot see where the following becomes part of the repl:

/examples
create-examples.js
lib/js/examples.js

Along the same lines, npm run build-examples is not working as it relies on babel-node which is not present.

Happy to help out, but I'm not sure what is needed here (or if everything is as it should be).

REPL - (CMD | CTRL) + / for commenting code out

I often find myself wanting to comment code out in the REPL. I think this is a standard keyboard shortcut for commenting code as it works is every REPL I can think of. I'd be glad to dig into it if it something that would be approved.

Tests

Looks like the other ramda* projects use Mocha, no objections if I bring it in here and add a few tests?

Move `bundle.js` out from `/lib/js`

I suggest that kind of "not-source" file should live in a separate /dist folder (or similar).

What do you good people think about this - and the folder structure in general?

Echo some error to screen when setup fails

Getting 503/Bad Gateway this morning from wzrd.in, which the repl relies on to host the scripts. Unfortunately when the scripts fail to load, the user does not get notified, they just stare at a non-functioning web site. We should tell the user something has gone wrong when something goes wrong.

Oh noes

Remove `?` from hash

Unless there is a reason that the ? is required, then it seems like parsing the code from the hash would be simpler if it didn't require removing the ? each time.

Repl not loading sanctuary and ramda-fantasy

The Repl at https://ramdajs.com/repl/ tries to load sanctuary@latest and ramda-fantasy@latest, both redirect to a specific version and then result in 500 and 503 responses.

The requests:
https://bundle.run/sanctuary@latest -> 302
https://bundle.run/ramda-fantasy@latest -> 302
https://bundle.run/[email protected] -> 503
https://bundle.run/[email protected] -> 500

I wanted to play around with Maybe and Either that is when I noticed something was wrong.

Remove navigation bar

If I understand correctly, an objective is to make this REPL embeddable so it can be included within the documentation example sections and in the "Try Ramda" page (and perhaps other places).

This suggest to me that it shouldn't carry around the navigation; that could belong to the page that contains the REPL.

Configuration

If we wish to reuse this on pages other than http://ramdajs.com/repl/ we might need to address some of these aspects - perhaps using some kind of configuration:

  • The google shortlink has an API KEY that relates to the above address; I presume we would want to configure it and the address rather than have them hardcoded.
  • We may not always want / need to update the address bar with the content of the input panel - this makes sense for sharing, but I'm not sure how it should work if we wish to reuse the repl to make dynamic examples on the docs page. I'd suggest that for those we could configure it to make a shortlink back to http://ramdajs.com/repl/ (or not at all).

REPL not working?

Error: Failed to load http://wzrd.in/standalone/sanctuary@latest

and in console:
bundle.js:52936 GET https://wzrd.in/standalone/sanctuary@latest net::ERR_INSECURE_RESPONSEload @ bundle.js:52936(anonymous function) @ bundle.js:354(anonymous function) @ bundle.js:63302(anonymous function) @ bundle.js:63302(anonymous function) @ bundle.js:63273(anonymous function) @ bundle.js:63304(anonymous function) @ bundle.js:63233(anonymous function) @ bundle.js:63290(anonymous function) @ bundle.js:63304(anonymous function) @ bundle.js:63233(anonymous function) @ bundle.js:355script.onload @ bundle.js:52948 bundle.js:52936 GET https://wzrd.in/standalone/ramda-fantasy@latest net::ERR_INSECURE_RESPONSE

Calls to browserify CDN failing everywhere

Whether I build and run this locally, or actually visit the repl in the docs, for the last few days I have been seeing all the browserify CDN calls 404s out for sanctuary and the other imported libs. This obviously ends the party right there, any one have the scoop on this?

Release on NPM

Thanks to @craigdallimore 's excellent work, we have a package that can be shared with others. We should do so. To prepare for this we need to:

  • add minification step #30
  • update the README to tell consumers how to use the repl API to do their bidding #31
  • set up travis #33
  • ???

Make goo.gl config optional

Hello,

I can understand that, in order to share short urls you need the credentials for go.gl and that stuff.
But there are many use-cases where this is not required.
Any chance you make this configuration option optional instead of required ?

Regards

RegeneratorRuntime is not defined

when i try to write a generator function in Repl, i get Error telling me that RegeneratorRuntime is not defined. Try it here: https://goo.gl/pwSSDJ

i think if the repl not include RegeneratorRuntime code, then the best thing to do is just leave the generator function as-is, ie don't transpile it to RegeneratorRuntime.

Share links broken in Safari

I'm not sure if this is a goo.gl issue or something with the REPL itself, but share links don't retain the # (or anything after it) on redirect in Safari.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.