• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    JavaScript
  • Created over 11 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

LambdaJS

The full ECMAScript API done a functional way.

RULES

  1. The data comes last. E.g: str.method(arg) -> method(arg, str)
  2. Everything is curried
  3. Functions with optional arguments are split into two functions. One with _ at the end that takes the options. E.g: indexOf(x,str) & indexOf_(x,y,str)
  4. Every function is pure

Thanks so much to @casperin and @eschmitt for doing a ton of the work on this though isn't not visible in the contributors.

DOCS

docs

USAGE

There is an expose() method to "mix in" to the global namespace if desired.

In the browser

<script src="dist/lambda.browser.js"></script>
<script>LambdaJS.expose(window);</script>

or

define(['dist/lambda.amd.js'], function(Ljs){
	
});

In node

npm install lambdajs
var ljs = require('lambdajs');

or

require('lambdajs').expose(global);

MOTIVATION

Let's say you want to replace "-" for "/" in a js function. Typically you'd have to do:

var dashesForSlashes = function(str) {
  return str.replace(/-/g, '/');
}

This has some issues.

  • We had to name a temporary variable str
  • We had to write some "glue code" - a full function(){} complete with return
  • We are dependent upon the str to be able to call replace

In functional "point free" style we don't need to grab a hold of our data to be able to write new functions. In this case, by "data" I mean the string.

LambdaJS let's us write something like this:

var dashesForSlashes = replace(/-/g, '/');

This is very useful when dealing with compose

var f = compose(toUpperCase, replace(/-/g, '/'))
f("hi-guys") //=> HI/GUYS

Another issue is, in standard javascript, if you call reverse on an array, you will permanently alter the array:

var users = ['Alex', 'Sam', 'Pat']
users.reverse(); //=> ['Pat', 'Sam' 'Alex']
users //=> ['Pat', 'Sam' 'Alex']

That can be quite surprising when you go to display users in a different spot of your app and they are out of order.

LambdaJS makes all the built-in functions "pure", meaning there is no side-effects or mutation.

var users = ['Alex', 'Sam', 'Pat']
reverse(users); //=> ['Pat', 'Sam' 'Alex']
users //=> [['Alex', 'Sam', 'Pat']

If you're interested in learning more about currying and composition, I gave a talk on this subject a little while ago: Hey underscore, you're doing it wrong!

ROADMAP (help if ya want!):

More Repositories

1

scoreunder

JavaScript
160
star
2

FPJS-Class

Learning the functional paradigm with js
JavaScript
94
star
3

typeclasses

Fun with typeclasses!
JavaScript
48
star
4

FunctionalJS

beefed up version of osteeles' library: http://osteele.com/sources/javascript/functional/
JavaScript
28
star
5

Fp101

html5devconf class
JavaScript
14
star
6

PreludeJS

A collection of functions often used with the functional paradigm
CoffeeScript
13
star
7

fpjsideas

ideas for a library set to create a full fp runtime
10
star
8

algebraic-validation

Semigroup + Monad for doing validations in Javascript
JavaScript
8
star
9

drbooleanchallenges

DrBoolean Boolean Challenges at SFJS
6
star
10

TiModules

various ti modules
Java
6
star
11

Fp101AbridgedClass

101 Point free functional programming class (abridged)
JavaScript
6
star
12

neo4j-test-server

A test neo4j server that runs jexp/neo4j-in-memory-server on port 7373 alongside your dev server.
Shell
5
star
13

AppCharity

JavaScript
5
star
14

node-neo4j-test

Node scripts and libraries for running neo4j server for your test suite.
JavaScript
3
star
15

palace

JavaScript
3
star
16

influxdb-archive

Archive data from InfluxDB
JavaScript
1
star
17

pfax-client

JavaScript
1
star
18

connectivesf

ConnectiveSF
JavaScript
1
star
19

Trippons-modules

PHP
1
star
20

Webcapsule-Mobile

JavaScript
1
star
21

mobileweb_proxy_server

This allows cross site to work on mobileweb
JavaScript
1
star
22

gi-node

GI-Node
JavaScript
1
star
23

Webcapsule-Mobile-V2

JavaScript
1
star
24

moo-phone

JavaScript
1
star
25

gonsterapp.com

CSS
1
star
26

goodtimes-infrastructure

The extra configuration needed beyond the microservice-template
Nginx
1
star
27

Simple-Support

Ruby
1
star
28

looprecur-website

JavaScript
1
star
29

njpf-site

PHP
1
star
30

lr-2012

PHP
1
star
31

NJPF-labelmaker

JavaScript
1
star
32

NCR

Ipad/iphone/android conference app
JavaScript
1
star
33

media_person

haskell media server that crops
Haskell
1
star