Slide 1

Slide 1 text

A better future for comprehensions Dave Herman

Slide 2

Slide 2 text

[for  (x  of  y)  if  (p(x))  f(x)]   (for  (x  of  y)  if  (p(x))  f(x))

Slide 3

Slide 3 text

• Parallel JS is moving in the direction of parallel pipelines – a natural fit for comprehensions. • Three strikes and you refactor! • LINQ: one comprehension syntax, unbounded number of (user-definable) traversable datatypes.

Slide 4

Slide 4 text

let  a  =  for  (x  of  a1)                      for  (y  of  a2)                          if  (y  >  x)                              {  x,  y  };

Slide 5

Slide 5 text

let  i  =  for  (x  of  map1.keys())                      for  (y  of  map2.keys())                          if  (y  >  x)                              {  x,  y  };

Slide 6

Slide 6 text

let  p  =  for  (x  of  a1.parallel())                      for  (y  of  a2.parallel())                          if  (y  >  x)                              {  x,  y  };

Slide 7

Slide 7 text

• The LINQ idea (which is actually the Haskell idea): comprehensions desugar into generic combinators. • Any datatype that supports those combinators automatically gets to play along.

Slide 8

Slide 8 text

• Defer comprehensions from ES6. • Jafar and I will present an ES7 proposal for generalized comprehensions.

Slide 9

Slide 9 text

Generator Iterator .prototype .prototype [[Prototype]] generator [[Prototype]] [[Prototype]] ??

Slide 10

Slide 10 text

Iterator.prototype.      zip      filter      map      ...

Slide 11

Slide 11 text

table.keys().map(...)                          .filter(...)   ! //  versus   ! import  {  map,  filter  }  from  "itertools";   filter(map(table.keys(),  ...),  ...);

Slide 12

Slide 12 text

(new  Iterator({      next()  {  ...  }   })).map(...)

Slide 13

Slide 13 text

5 Jun 14 Resolutions

Slide 14

Slide 14 text

• Agree to defer comprehensions. • No future-proofing placeholder objects (can be added later with low compatibility risk). • May not generalize generator comprehensions since first RHS eagerly evaluated; more work to do.