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

Return was a mistake #689

Closed
Orace opened this issue Nov 11, 2019 · 6 comments
Closed

Return was a mistake #689

Orace opened this issue Nov 11, 2019 · 6 comments

Comments

@Orace
Copy link
Contributor

Orace commented Nov 11, 2019

#636 should not have been merged.

Return is an awful method name

  • return is a c# instruction, and use this word for a method is a really bad idea
  • Return doesn't give any clue of what the methods do
  • Used with a using static MoreEnumerable; it's just not readable:
  source.Select(Return);
  return Return(x);

It's about building a IEnumerable, it can be generalized and that should be MoreEnumerable.From (see #690) with different overload (param T[] being the start point).
The single item case can be optimized later.
If we need a special name for it, it should be something like Encapsulate, Wrap, Pack, Box, ... Anything that bring the idea of building a container around the element.

Return is an alias for a simple stuff

  • MoreEnumerable.Return is almost x => new[] { x }; it does not even shorten the summoning.

What about immutable list stuff ?

If the target functionality was to build immutable list, just generalize it:

IList<T> ToImmutableList<T>(this IEnumerable<T> source);  // the returned list is readonly.

return IReadonlyList is not enough since it doesn't provide CopyTo optimized methods.

@Orace
Copy link
Contributor Author

Orace commented Nov 11, 2019

We also can have ImmutableList.From factories.

@atifaziz
Copy link
Member

This has all been discussed, including choice of names, in #615.

/cc @MitchBodmer

@atifaziz
Copy link
Member

/remind me about closing this in one week if there are no further comments.

@reminders reminders bot added the reminder label Nov 14, 2019
@reminders
Copy link

reminders bot commented Nov 14, 2019

@atifaziz set a reminder for Nov 21st 2019

@reminders reminders bot removed the reminder label Nov 21, 2019
@reminders
Copy link

reminders bot commented Nov 21, 2019

👋 @atifaziz, about closing this if there are no further comments.

@atifaziz
Copy link
Member

Closing as there's been no follow-up.

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

No branches or pull requests

2 participants