Skip to content

Adds append, appendAll and prepend to Buffer#6879

Merged
julienrf merged 1 commit intoscala:2.13.xfrom
Prithvirajbilla:10970
Jul 10, 2018
Merged

Adds append, appendAll and prepend to Buffer#6879
julienrf merged 1 commit intoscala:2.13.xfrom
Prithvirajbilla:10970

Conversation

@Prithvirajbilla
Copy link
Copy Markdown
Contributor

@scala-jenkins scala-jenkins added this to the 2.13.0-M5 milestone Jul 3, 2018
* @param elems the elements to append.
*/
@deprecated("Use addAll instead", "2.13.0")
def append(elems: A*) { appendAll(elems) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to not use the procedure syntax (which has been deprecated), and to forward to addAll directly:

def append(elems: A*): Unit = addAll(elems)
def appendAll(xs: IterableOnce[A]): Unit = addAll(xs)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. thanks.

*/
def prepend(elem: A): this.type

@`inline` final def append(elem: A): this.type = addOne(elem)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this one? Users will end up with the deprecated (and less efficient) version instead. I don't think it makes sense to deprecate append when prepend is still supported.

Copy link
Copy Markdown
Contributor

@julienrf julienrf Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I forgot about that (see #6819 )…

So, do we want to have both append and appendAll, in addition to addOne and addAll, but for the sake of symmetry with prepend and prependAll?

* @param elems the elements to append.
*/
@deprecated("Use addAll instead", "2.13.0")
def append(elems: A*): Unit = addAll(elems)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecated methods should be @inline final. Otherwise they are prone to getting overridden (which may not have the intended semantics).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making them @deprecatedOverriding instead of final to not break existing overrides?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @deprecatedOverriding and @inline tag.

@julienrf
Copy link
Copy Markdown
Contributor

julienrf commented Jul 5, 2018

Hey @Prithvirajbilla, thanks a lot for your work. However, I gave you a wrong direction in the initial issue description and I’m sorry about that. I’ve explained in scala/bug#10970 (comment) what I think we should do instead. We appreciate a lot if you still want to fix the issue, just let us know!

@Prithvirajbilla
Copy link
Copy Markdown
Contributor Author

I'd like to fix the issue. have gone through your comments. I will send a PR this weekend.

@Prithvirajbilla Prithvirajbilla changed the title adds deprecated methods append and appendAll to Buffer Adds append, appendAll and prependAll to Buffer Jul 8, 2018
@Prithvirajbilla Prithvirajbilla changed the title Adds append, appendAll and prependAll to Buffer Adds append, appendAll and prepend to Buffer Jul 8, 2018
@Prithvirajbilla
Copy link
Copy Markdown
Contributor Author

Updated:

  • added append and appendAll, and made addOne and addAll final aliases to these methods. with same signature this.type.
  • added deprecated variadic versions of append and prepend with same signature as addOne or addAll which is this.type.

Copy link
Copy Markdown
Contributor

@julienrf julienrf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good! Can you make the aliases @inline and then squash the commits?

*
* @param elem the element to append.
*/
final def append(elem: A): this.type = addOne(elem)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could keep the @inline annotation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

/** Appends the elements contained in a iterable object to this buffer.
* @param xs the iterable object containing the elements to append.
*/
final def appendAll(xs: IterableOnce[A]): this.type = addAll(xs)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be @inline too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@SethTisue
Copy link
Copy Markdown
Member

this needs further work, see
scala/bug#11112

@Prithvirajbilla
Copy link
Copy Markdown
Contributor Author

what do you recommend that we do here?

revert overloaded append method or fixing type inference issue.

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

Successfully merging this pull request may close these issues.

5 participants