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

Allow [] as a synonym for Set.contains() #416

Closed
DartBot opened this issue Nov 10, 2011 · 5 comments
Closed

Allow [] as a synonym for Set.contains() #416

DartBot opened this issue Nov 10, 2011 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 10, 2011

This issue was originally filed by rice@google.com


It would be a nice shorthand to define '[x]' on a set to return the same value as s.contains(x).

@DartBot
Copy link
Author

DartBot commented Nov 11, 2011

This comment was originally written by drfibonacci@google.com


Added Triaged label.

@rakudrama
Copy link
Member

Would you expect s['fred'] = false; to remove the element?

I think consideration of what is a nice API for Set should happen at the level of the whole library.
For example, should it be possible to implement a data structure that is both a Set and a List (and a PriorityQueue)?
If the interfaces Set, List, PriorityQueue are considered in isolation then conflicts in usage will happen.

I personally would prefer to write
   if('fred' in s)...
than
   if (s['fred']) ...

@DartBot
Copy link
Author

DartBot commented Jun 28, 2012

This comment was originally written by aj...@gmail.com


Me too, coming from a python background. x in y is very nice syntax, and more immediately obvious.

@lrhn
Copy link
Member

lrhn commented Jun 29, 2012

I don't generally mind redundance if it makes it easier to express what you want, but I think two functions that does exactly the same is too much.
A set is not a Map to bool, nor is it a function to bool (you could write set(x) too to get the same result as set.contains(x)). I'd prefer to keep separate concepts distinct.
If you want a map, you should be able to somehow get a Map<T,bool> view of a Set<T> so you can treat it as a Map (fully with assigning false to the map meaning remove from the set), but it won't be one itself. (If you want a it as a function, just extract the "contains" method).

In other words, I don't think we should do this. The []-operator is for indexing into something. A set is, conceptually, not indexable by anything. The operator doesn't really match the operation.

If 'in' was an operator, I wouldn't mind using it, but it isn't.

@lrhn
Copy link
Member

lrhn commented Sep 25, 2012

Added WontFix label.

@DartBot DartBot added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Sep 25, 2012
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
nex3 pushed a commit that referenced this issue Aug 31, 2016
Fix build after runtime commit (bad merge)
copybara-service bot pushed a commit that referenced this issue Jun 2, 2022
Changes:
```
> git log --format="%C(auto) %h %s" 5699caf..e3f4bd2
 https://dart.googlesource.com/markdown.git/+/e3f4bd2 example: update CDN asset links (#435)
 https://dart.googlesource.com/markdown.git/+/a678bfc example: add GitHub markdown CSS (#434)
 https://dart.googlesource.com/markdown.git/+/bc79c43 Merge pull request #425 from dart-lang/pq-patch-1
 https://dart.googlesource.com/markdown.git/+/4e8aa03 add pub badge
 https://dart.googlesource.com/markdown.git/+/7987e1e Remove dependency on third party package:charcode.
 https://dart.googlesource.com/markdown.git/+/90995fd Split block_parser.dart and inline_parser.dart (#422)
 https://dart.googlesource.com/markdown.git/+/8bb9062 Add trailing commas to some parameter lists to get better formatting (#420)
 https://dart.googlesource.com/markdown.git/+/1c5f2e7 Enable raw strings lint rules (#418)
 https://dart.googlesource.com/markdown.git/+/4784153 Enable use_if_null_to_convert_nulls_to_bools lint rule (#417)
 https://dart.googlesource.com/markdown.git/+/0d67e99 Enable prefer_interpolation_to_compose_strings (#416)
 https://dart.googlesource.com/markdown.git/+/5561351 Enable prefer_final_locals lint rule (#415)
 https://dart.googlesource.com/markdown.git/+/6d39147 Create DelimiterSyntax to replace TagSyntax (#407)
 https://dart.googlesource.com/markdown.git/+/4f4e899 Add caseSensitive parameter on the InlineSyntax constructor (#400)
 https://dart.googlesource.com/markdown.git/+/e16aff0 Check parser.isDone when title is null in _parseInlineBracketedLink (#394)
 https://dart.googlesource.com/markdown.git/+/3471578 Use `Uri.toFilePath()` instead of `Uri.path` for locating tests (#396)

```

Diff: https://dart.googlesource.com/markdown.git/+/5699cafa9ef004875fd7de8ae9ea00e5295e87a4~..e3f4bd28c9e61b522f75f291d4d6cfcfeccd83ee/
Change-Id: Ie04b17dfcce57fcd9e814bd8b9a09677a91136d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246984
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants