Skip to content
another javascript functional library
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.hgignore
LICENSE.html
README.html
nbactions.xml
pom.xml

README.html

<!doctype html>
<html lang="en">
    <head>
        <title>LambdaScript 2.0</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <h1>LambdaScript ${pom.version}</h1>

        <p>
            LambaScript is intended to be a practical functional
            library rather than elegant, beautiful or minimal one.
        </p>

        <p>Version 2 is not backward compatible with version 1.0:</p>
        <ul>
            <li>lazymap</li>
            <li>don't build NullIterator when argument is null or undefined</li>
            <li>type(object) == 'array' renamed to isArray()</li>
            <li>toArray now is a function, not a method of Iterable</li>
            <li>consistent naming</li>
            <li>preconditions</li>
            <li>using jasmine for testing</li>
        </ul>

        <h2>Usage</h2>

        <pre>
&lt;script language="text/javascript" src="lambdascript.js"&gt;&lt;/script&gt;

&lt;script language="text/javascript"&gt;
    LambdaScript.install();

    map([1, 2, 3], lambda('a*a')) // [1, 4, 9]

    // filter 
    filter([-3, 4, 5, -6, -42], lambda('a>0')) // [4, 5] 

    // reduce
    function sum() {
       return reduce(arguments, lambda('a+b'));
    }

    sum(1,2,3)  // 6

    // factorial
    function fact(n) {
      return reduce(range(n), lambda('a*b'));
    }

    fact(5) // 120

    // curry
    var mul = lambda('a*b');
    var mul_by2 = curry(mul, 2);
    var mul_by3 = curry(mul, 3);
    mul_by2(21) // 42
    mul_by3(14) // 42

    // range
    range(3)           // [1, 2, 3] 
    range(5, 7)       // [5, 6, 7]
    range(1, 10, 2) // [1, 3, 5, 7, 9]
&lt;/script&gt;
        </pre>


        <h2>Build documentation</h2>
        In order to build documentation:
        <pre>
$ mvn jsdoctk:jsdoc
        </pre>


        <h2>See also</h2>
        <ul>
            <li>
                <a href="http://crockford.com/onjs/2.ppt">On Javascript
                    by Crockford</a>
            </li>
            <li>
                <a href="http://interglacial.com/hoj/hoj.html">High
                    Order JavaScript</a>
            </li>
            <li>clojure, in particular
                <a href="http://richhickey.github.com/clojure/clojure.core-api.html">core API</a>
            </li>
            <li>
                <a href="http://bitbucket.org/dfa/dollar">Dollar</a>
            </li>
            <li>
                <a href="http://osteele.com/sources/javascript/functional/">Functional Javascript</a>
            </li>  	
            <li>
                <a href="http://documentcloud.github.com/underscore">underscore</a></li>
            <li>
                <a href="http://github.com/runarorama/LambdaScript/">LambdaScript</a>
            </li>
        </ul>

        <h2>TODO</h2>

        <p>My personal wishlist:</p>

        <ul>
            <li>custom parameters names such as lambda("x,y: x + y") or just detect them</li>
            <li>parameterless lambda
                (see <a href="http://debasishg.blogspot.com/2007/11/erlang-string-lambdas.html">Erlang
                    string lambdas</a>)</li>
            <li>pipe(function1, function2, ...) (like -> macro in clojure)</li>
            <li>map(fn, iterable1, iterable2, ...iterableN)</li>
            <li>unzip()</li>
            <li>reverse(iterable)</li>
            <li>sort()</li>
            <li>sortBy()</li>
            <li>repeat(fn, n) // repeat a function n times</li>
            <li>union(iterable1, iterable2, ...iterableN)</li>
            <li>intersect(iterable1, iterable2 ... iterableN)</li>
            <li>max(iterable)</li>
            <li>min(iterable)</li>
            <li>concat(iterable1, iterable2, ...iterableN)</li>
            <li>join(iterable, [sep])</li>
            <li>interpose(iterable1, value)</li>
        </ul>
    </body>
</html>
You can’t perform that action at this time.