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


Groups > comp.lang.javascript > #29029

Re: ES6 itertools

Newsgroups comp.lang.javascript
Date 2015-12-22 08:37 -0800
References <n4shlq$huj$1@solani.org>
Message-ID <1870a461-01b3-4962-b6c6-d2dbcdc86bd7@googlegroups.com> (permalink)
Subject Re: ES6 itertools
From Scott Sauyet <scott.sauyet@gmail.com>

Show all headers | View raw


Asen Bozhilov wrote:
> I am working on project called ES-Iter 
>     <URL: https://github.com/abozhilov/ES-Iter>. 
> [ ... ]
> I am open for discussion, and contributions. Any improvements are
> welcome.

How different do you find this from libraries such as Lazy [1] or 
lz.js [2]? 

I think it would be useful if you could support as much of the 
FantasyLand specification [3] as possible. For instance, your `map` 
method [4] looks almost certain to support FantasyLand's Functor laws 
[5], so an Iter instance should be a Functor, and can be manipulated 
like any other Functor. But if you also supplied `chain` (it looks 
like your `flatMap` with the `deep` parameter set to false) you could 
support another of the specifications. You could probably support many 
of the specifications of FantasyLand. 

FantasyLand has been growing as a way to describe abstract, algebraic 
types. 

From my perspective as one of the authors of Ramda [6], this would 
make working with Iter very easy: 


    const R = require('ramda'); // general-purpose utility lib
    const Maybe = require('data.maybe'); // Folktale Maybe (is Functor)

    // All are functors
    R.map(square, [1, 2, 3, 4, 5]); //=> [1, 4, 9, 16, 25]
    R.map(square, Maybe.Just(7)); //=> Maybe.Just(49)
    R.map(square, Maybe.Nothing); //=> Maybe.Nothing
    R.map(square, new Iter([1, 2, 3]); //=> ~ new Iter([1, 4, 9])

    // But other Ramda integration should also work
    let fibo = new Iter(function* () {
        let [a, b] = [0, 1];
        while(true) {
            yield a;
            [a, b] = [b, a + b]
        }
    });

    R.compose(R.take(6), square)(fibo);
    //=> [0 * 0, 1 * 1, 1 * 1, 2 * 2, 3 * 3, 5 * 5] 
    //~~> [0, 1, 1, 4, 9, 25]

    
Note that Ramda's delegation to your code is independent of your
implementing the FantasyLand specifications, but if you do
implement them, then certain advanced behavior automatically
applies.  And people could use Iter with other common tools that
know the specification, but not the details of your API.


  [1]: http://danieltao.com/lazy.js/
  [2]: https://github.com/goatslacker/lz
  [3]: https://github.com/fantasyland/fantasy-land
  [4]: https://github.com/abozhilov/ES-Iter#mapcallback--x--x
  [5]: https://github.com/fantasyland/fantasy-land#functor
  [6]: http://ramdajs.com/

  -- Scott

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


Thread

ES6 itertools Asen Bozhilov <asen.bozhilov@gmail.com> - 2015-12-16 22:30 +0200
  Re: ES6 itertools Scott Sauyet <scott.sauyet@gmail.com> - 2015-12-22 08:37 -0800

csiph-web