Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24533

Re: ANN: Ramda, a new functional programming library

Newsgroups comp.lang.javascript
Date 2014-06-01 19:28 -0700
References <da2909bd-58cc-4183-8b3c-167039985491@googlegroups.com> <1wrr3wcXt2iTFwiZ@invalid.uk.co.demon.merlyn.invalid>
Message-ID <586acd4a-249d-4a91-a71a-9cd6187634dd@googlegroups.com> (permalink)
Subject Re: ANN: Ramda, a new functional programming library
From Scott Sauyet <scott.sauyet@gmail.com>

Show all headers | View raw


Dr J R Stockton wrote:
> Scott Sauyet posted:
> 
>> I'm looking for feedback on a new functional programming library for
>> Javascript that I've been developing with a friend.  [ ... ]
> 
> If the library is not being written IN JavaScript (or even if it is),
> you could consider implementing (maybe more efficiently) the improved
> date object in <http://www.merlyn.demon.co.uk/js-dobj2.htm>. [ ... ]

Although that looks to be interesting code, and an improvement on 
the existing Date constructor function in several important ways, I 
don't think it would be a good fit for Ramda.  

Ramda is about offering functional programming (FP) tools to the 
user.  Javascript, with heritage from both Self and Scheme has both 
object-oriented and functional roots.  There are plenty of tools to 
help with the OO side, but far fewer for the FP paradigm.  That's 
where Ramda fits in.  It offers things like improved `map`, 
`reduce`, `filter`, and similar list-handling features, functional 
composition and currying, the reification of numerous functions from 
the String, Array, and Object prototypes, some SQL-like functions to 
query lists of objects, and various other techniques to work with
immutable objects.

DATE2 is an OO construct, a constructor function with a beefy 
prototype object.  It creates mutable objects, usually a no-no in FP 
code, and it carries a great deal of inaccessible internal state.  
These features are fine for OO, but not for FP.

I have a talk I've given several times discussing the ideas involved 
in functional programming as applied to Javascript. [1]  In this I 
work through an example of some of the common functional programming 
tools in Javascript, developing this fairly simple FP function of 
the parameter `memberName`:

    fetchData()
      .then(get('tasks'))
      .then(filter(propEq('member', memberName)))
      .then(reject(propEq('complete', true)))
      .then(map(pick(['id', 'dueDate', 'title', 'priority'])))
      .then(sortBy(get('dueDate')));

out of this much more lengthy procedural version:

    fetchData()
      .then(function(data) {
        return data.tasks;
      })
      .then(function(tasks) {
        var results = [];
        for (var i = 0, len = tasks.length; i < len; i++) {
          if (tasks[i].member == memberName) {
            results.push(tasks[i]);
          }
        }
        return results;
      })
      .then(function(tasks) {
        var results = [];
        for (var i = 0, len = tasks.length; i < len; i++) {
          if (!tasks[i].complete) {
            results.push(tasks[i]);
          }
        }
        return results;
      })
      .then(function(tasks) {
        var results = [], task;
        for (var i = 0, len = tasks.length; i < len; i++) {
          task = tasks[i];
          results.push({
            id: task.id,
            dueDate: task.dueDate,
            title: task.title,
            priority: task.priority
          })
        }
        return results;
      })
      .then(function(tasks) {
        tasks.sort(function(first, second) {
          return first.dueDate - second.dueDate;
        });
        return tasks;
      });

The first block is the kind of code we're trying to promote through 
Ramda.

So thank you for your offer.  And if you have other tools that you 
think might fit, do please let us know.

  -- Scott

[1] <http://scott.sauyet.com/Javascript/Talk/FunctionalProgramming>

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-27 20:13 -0700
  Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-27 21:00 -0700
    Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 04:37 -0700
  Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 04:36 -0700
  Re: ANN: Ramda, a new functional programming library "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-05-28 08:49 -0700
    Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 15:59 -0700
      Re: ANN: Ramda, a new functional programming library "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-05-28 16:15 -0700
        Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-28 17:05 -0700
          Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-30 14:53 +0200
            Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 11:14 -0700
  Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-05-29 19:40 +0100
    Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-29 17:55 -0700
      Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-30 14:05 +0200
        Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 11:10 -0700
  Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-30 06:25 -0700
    Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 11:23 -0700
      Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-30 12:44 -0700
        Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-30 13:39 -0700
          Re: ANN: Ramda, a new functional programming library John C <rescattered@gmail.com> - 2014-05-30 19:17 -0700
            Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-05-31 09:52 -0700
              Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-31 22:24 +0200
                Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-01 06:55 -0700
      Re: ANN: Ramda, a new functional programming library Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-31 21:00 +0200
        Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-01 06:54 -0700
  Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-01 19:05 +0100
    Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-01 19:28 -0700
      Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-03 22:01 +0100
        Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-03 19:15 -0700
          Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-05 23:41 +0100
            Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-06 11:36 -0700
          Re: ANN: Ramda, a new functional programming library Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-06-07 23:13 +0100
  Re: ANN: Ramda, a new functional programming library billyroberts111@gmail.com - 2016-03-06 10:22 -0800
    Re: ANN: Ramda, a new functional programming library Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-06 17:52 -0800
      Re: ANN: Ramda, a new functional programming library "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-07 10:50 +0100

csiph-web