Skip to content

doc: improve Option::map example#25920

Merged
bors merged 1 commit into
rust-lang:masterfrom
tshepang:option-map-example
Jun 2, 2015
Merged

doc: improve Option::map example#25920
bors merged 1 commit into
rust-lang:masterfrom
tshepang:option-map-example

Conversation

@tshepang

Copy link
Copy Markdown
Member

No description provided.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

Comment thread src/libcore/option.rs Outdated

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 is this even being made into a String?

@Gankra

Gankra commented May 31, 2015

Copy link
Copy Markdown
Contributor

It's not clear to me that this really "improves" anything. It just makes the example more complicated.

@tshepang

Copy link
Copy Markdown
Member Author

num_as_int tells me the string 10 is now represented as the int 10. This is more sensible than checking the length of that string.

It's also nice to do an assert there, so we actually make use of those bindings, instead of just assign values.

BTW, feel free to improve this example.

@Gankra

Gankra commented Jun 1, 2015

Copy link
Copy Markdown
Contributor

I agree the variable names are unfortunate. How about:

/// let maybe_some_string = Some("hello!".to_string());
/// let maybe_some_len = maybe_some_string.map(|s| s.len());
///
/// assert_eq!(maybe_some_len, Some(6));

@tshepang

tshepang commented Jun 1, 2015

Copy link
Copy Markdown
Member Author

nice suggestion... done!

@Gankra

Gankra commented Jun 1, 2015

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Jun 1, 2015

Copy link
Copy Markdown
Collaborator

📌 Commit 8221715 has been approved by Gankro

Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 2, 2015
bors added a commit that referenced this pull request Jun 2, 2015
@bors bors merged commit 8221715 into rust-lang:master Jun 2, 2015
@tshepang tshepang deleted the option-map-example branch June 2, 2015 11:37
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