Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comprehensions #31

Closed
StoneCypher opened this issue Dec 18, 2018 · 10 comments
Closed

Comprehensions #31

StoneCypher opened this issue Dec 18, 2018 · 10 comments

Comments

@StoneCypher
Copy link

StoneCypher commented Dec 18, 2018

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
Copy link
Member

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

@bakkot
Copy link
Contributor

bakkot commented Dec 18, 2018

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

@bakkot bakkot closed this as completed Dec 18, 2018
@ljharb
Copy link
Member

ljharb commented Dec 18, 2018

@StoneCypher
Copy link
Author

@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
Copy link
Author

@ljharb - thanks

@bakkot
Copy link
Contributor

bakkot commented Dec 18, 2018

what about things that involve both syntax and functions?

Those also wouldn't be in scope for this.

@StoneCypher
Copy link
Author

image

@StoneCypher
Copy link
Author

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

@trotyl
Copy link

trotyl commented Dec 19, 2018

@StoneCypher This repo is not for raising any feature request, #32 is going to make it clear.

@bakkot
Copy link
Contributor

bakkot commented Dec 19, 2018

#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants