dart-lang / dart-lang/language

Add * operator to elements in a list

Open
#439 3 comments 0 reactions 0 assignees View on GitHub
request
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

For string, we have the `*` operator, which as we know turns a single item into multiple.
This would be handy in `Lists` for example, instead of writing
```dart
[MyObject(), MyObject() ,MyObject()]
```
It would be easier to write, [...MyObject() * 3]
I do, however, see a huge issue with this if the object has a `*` operator defined, then how would you know the difference...

> operator * method
> String operator * (
> int times
> )
> Creates a new string by concatenating this string with itself a number of times.
>
> The result of str * n is equivalent to str + str + ...(n times)... + str.
>
> Returns an empty string if times is zero or negative.
>
> Implementation
> String operator *(int times);

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.