-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix String.split/3 example in guide and add note in docs #14223
Conversation
Will backport this after merge |
@@ -33,14 +33,14 @@ We can also use options to limit the splitting algorithm to a maximum number of | |||
|
|||
```elixir | |||
iex> String.split("1 2 3", " ", [trim: true, parts: 2]) |
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 wonder if we should pick another example now? Although the only other option that comes to mind is inspect
.
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.
Another option is to invert the examples: first we show the parts option and then we show the trimming one. It may be more logical.
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.
how about to_timeout?
it's in Kernel, and very easy to understand
to_timeout(hour: 1, minute: 30)
5400000
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.
Oh but people who installed an old version might not have it
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.
Or this example from inspect
examples is nice
inspect([1, 2, 3], pretty: true, width: 0)
"[1,\n 2,\n 3]"
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.
On the other hand it requires additional context on where timeouts are used? There is always Date.shift though.
If we assume people have a recent enough version of Elixir, I think the context can be pretty minimal and the examples natural enough. We could say something like
Various functions in Elixir or Erlang libraries accept a timeout in milliseconds. For these cases, we can use the
to_timeout
helper:iex> to_timeout([minute: 1]) 60000 iex> to_timeout([minute: 1, second: 30]) 90000 iex> to_timeout(minute: 1, second: 30) 90000
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.
Another example using just primitive types (I don't love it):
iex(1)> Base.encode32("foobar")
"MZXW6YTBOI======"
iex(2)> Base.encode32("foobar", case: :lower)
"mzxw6ytboi======"
iex(3)> Base.encode32("foobar", case: :lower, padding: false)
"mzxw6ytboi"
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.
Let’s try keeping as is but different order. Do you want me to push something?
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.
If that doesn’t work, I think Base can be a good second option.
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.
Let’s try keeping as is but different order.
Sorry I didn't get it 😅
Do you want me to push something?
Yes please 🙏
Co-authored-by: José Valim <[email protected]>
Close #14222