tc39 / proposal-built-in-modules

BSD 2-Clause "Simplified" License
891 stars 25 forks source link

Comprehensions #31

Closed StoneCypher closed 5 years ago

StoneCypher commented 5 years ago

It's honestly kind of hard to explain just how useful comprehensions actually are

Like a third of my code in erlang ends up using them somehow

function rem(item, list) {

  const copy  = list.slice(),
        index = copy.findIndex(o => o.class === 'two');

  if (index !== -1) { copy.splice(index, 1); }

  return copy;

}

// this basically reduces permutation to a one-liner

function permute(List) {

  // the permutation of an empty list is the list containing one empty list
  if (list.length === 0) { return [ [] ]; } 

  // this will go over list, using each element for item once, then remove it
  // and use the remainder for tail
  return [ [Item].concat(Tail) || Item <- List, Tail <- permute(rem(Item, List)) ];

}
nicolo-ribaudo commented 5 years ago

Thank you @StoneCypher, but this proposal is about standard functions, not new syntax.

bakkot commented 5 years ago

Syntax isn't really in scope for this proposal. You might suggest it on es-discuss (or find one of the previous threads there).

ljharb commented 5 years ago

You may find these relevant:

StoneCypher commented 5 years ago

@nicolo-ribaudo , @bakkot - oh, didn't recognize the difference. scuttled another one of these sob stories i'm writing, as a result.

what about things that involve both syntax and functions?

StoneCypher commented 5 years ago

@ljharb - thanks

bakkot commented 5 years ago

what about things that involve both syntax and functions?

Those also wouldn't be in scope for this.

StoneCypher commented 5 years ago

image

StoneCypher commented 5 years ago

If I had four array functions to suggest and two object functions to suggest, would you want one issue, two, or six?

trotyl commented 5 years ago

@StoneCypher This repo is not for raising any feature request, https://github.com/tc39/proposal-javascript-standard-library/pull/32 is going to make it clear.

bakkot commented 5 years ago

16 is a reasonable place to make suggestions for library features, I think. It's helpful to have an idea of what might go into such a library.