You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pop quiz: what does this program print. In particular, what will the first call to next() return when we are doing a split over the empty string? (Also, should it do something else? But that's not as important to me as making the doc clear.)
fntake_three<'a,I:Iterator<&'astr>>(input:&str,variant:&str,muti:I){let fst = i.next();let snd = if fst.is_some(){ i.next()}else{None};let thd = if snd.is_some(){ i.next()}else{None};println!("{:8} {:3}: {} {} {}",
format!("`{}`", input), variant, fst, snd, thd);}fnmain(){let i = "a.b";take_three(i,"", i.split('.'));let i = ".";take_three(i,"", i.split('.'));let i = "";take_three(i,"", i.split('.'));let i = "a.b";take_three(i,"n1", i.splitn('.',1));let i = ".";take_three(i,"n1", i.splitn('.',1));let i = "";take_three(i,"n1", i.splitn('.',1));let i = "a.b";take_three(i,"n0", i.splitn('.',0));let i = ".";take_three(i,"n0", i.splitn('.',0));let i = "";take_three(i,"n0", i.splitn('.',0));}
(To be fair: this is not one of those trick questions where splitn's behavior deviates from split on the empty string. If you have the correct intuition about how one behaves, then you'll have the right intuition for the other. But I didn't have an intuition in either direction, which led me to first consult the doc.)
The text was updated successfully, but these errors were encountered:
Here's the doc for
str::split
andstr::splitn
:http://static.rust-lang.org/doc/master/core/str/trait.StrSlice.html#tymethod.split
Pop quiz: what does this program print. In particular, what will the first call to
next()
return when we are doing a split over the empty string? (Also, should it do something else? But that's not as important to me as making the doc clear.)(To be fair: this is not one of those trick questions where
splitn
's behavior deviates fromsplit
on the empty string. If you have the correct intuition about how one behaves, then you'll have the right intuition for the other. But I didn't have an intuition in either direction, which led me to first consult the doc.)The text was updated successfully, but these errors were encountered: