-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Keep backwards compatibility on Range and Date.Range #11117
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
Keep backwards compatibility on Range and Date.Range #11117
Conversation
lib/elixir/lib/enum.ex
Outdated
| end | ||
|
|
||
| # TODO: Remove me on v2.0 | ||
| def reduce(%{__struct__: Range, first: first, last: last} = range, acc, fun) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we don't need this clause because it will fallback to the protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right
iex(6)> Enum.reduce(old_range, 0, fn a, b -> a + b end)
55
|
Thanks @lukaszsamson, however I believe those changes are not necessary, except for the daterange ones. Can you please keep only them and add some tests? thank you. |
|
@josevalim I reverted not needed changes and added test coverage |
v0idpwn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick for consistency
|
|
||
| # TODO: Remove me on v2.0 | ||
| def member?( | ||
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| %Date.Range{first_in_iso_days: first_days, last_in_iso_days: last_days} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not pattern matching on range on purpose because those are "old versions" of the range. In theory the pattern works, because we don't check the size, but I would prefer to keep it explicit it is a subset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL, sorry for noise :)
| def slice( | ||
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | ||
| date_range | ||
| ) do | ||
| step = if first_days <= last_days, do: 1, else: -1 | ||
| slice(Map.put(date_range, :step, step)) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def slice( | |
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| slice(Map.put(date_range, :step, step)) | |
| end | |
| def slice( | |
| %Date.Range{first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| slice(Map.put(date_range, :step, step)) | |
| end |
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | ||
| date_range, | ||
| acc, | ||
| fun | ||
| ) do | ||
| step = if first_days <= last_days, do: 1, else: -1 | ||
| reduce(Map.put(date_range, :step, step), acc, fun) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range, | |
| acc, | |
| fun | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| reduce(Map.put(date_range, :step, step), acc, fun) | |
| end | |
| %Date.Range{first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range, | |
| acc, | |
| fun | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| reduce(Map.put(date_range, :step, step), acc, fun) | |
| end |
| # TODO: Remove me on v2.0 | ||
| defp size( | ||
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | ||
| date_range | ||
| ) do | ||
| step = if first_days <= last_days, do: 1, else: -1 | ||
| size(Map.put(date_range, :step, step)) | ||
| end | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # TODO: Remove me on v2.0 | |
| defp size( | |
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| size(Map.put(date_range, :step, step)) | |
| end | |
| # TODO: Remove me on v2.0 | |
| defp size( | |
| %Date.Range{first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| size(Map.put(date_range, :step, step)) | |
| end | |
| # TODO: Remove me on v2.0 | ||
| defp empty?( | ||
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | ||
| date_range | ||
| ) do | ||
| step = if first_days <= last_days, do: 1, else: -1 | ||
| empty?(Map.put(date_range, :step, step)) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # TODO: Remove me on v2.0 | |
| defp empty?( | |
| %{__struct__: Date.Range, first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| empty?(Map.put(date_range, :step, step)) | |
| end | |
| # TODO: Remove me on v2.0 | |
| defp empty?( | |
| %Date.Range{first_in_iso_days: first_days, last_in_iso_days: last_days} = | |
| date_range | |
| ) do | |
| step = if first_days <= last_days, do: 1, else: -1 | |
| empty?(Map.put(date_range, :step, step)) | |
| end |
|
|
||
| # TODO: Remove me on v2.0 | ||
| def inspect(%{__struct__: Date.Range, first: first, last: last} = date_range, opts) do | ||
| step = if first <= last, do: 1, else: -1 | ||
| inspect(Map.put(date_range, :step, step), opts) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # TODO: Remove me on v2.0 | |
| def inspect(%{__struct__: Date.Range, first: first, last: last} = date_range, opts) do | |
| step = if first <= last, do: 1, else: -1 | |
| inspect(Map.put(date_range, :step, step), opts) | |
| end | |
| # TODO: Remove me on v2.0 | |
| def inspect(%Date.Range{first: first, last: last} = date_range, opts) do | |
| step = if first <= last, do: 1, else: -1 | |
| inspect(Map.put(date_range, :step, step), opts) | |
| end |
|
💚 💙 💜 💛 ❤️ |
Carmen675
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I DONT CODE I SONT KNOW HOW I JUST WANT WHO EVER HAS TAKEN OVER MY PHONE TO PLEASE STOP PUTTING MALWARE ON MY IPHONE AND SLOWLY TURNING MY PHONE INTO A ANDROID THATS GOING TO BE THEIRS. I HAVE HAD NO IDEA SOMEONE WAS DOING THIS TRACKING MY EVERY MOVE, RECORDING MY PHONE CALLS WHEN I USED TO GET THEM NOW NO CALLS OR TEXTS HARDLY ANYTHING AT ALL
Fixes #11110
Handles cases not covered by 13ba96b
There are 2 more usages but those look safe. If I understand it correctly they happen only on compile time
elixir/lib/elixir/lib/kernel.ex
Line 4071 in 58ca652
elixir/lib/elixir/lib/kernel.ex
Line 4077 in 58ca652