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
Add takeTo to Traversable #2963
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2963?orig=1 |
@dcsobral said: collection.takeTo(p).init == collection.takeWhile(!p) Though I only now realize I mistyped it. |
@paulp said:
More likely because you're suggesting library changes at about the worst possible time. FWIW I want this function all the time as well, but please let us try to ship 2.8. That means live with the library the way it is short of glaring bugs. The faster we ship the faster I can open the greenhouse. |
@SethTisue said: I not infrequently find myself wanting this (takeTo/dropTo/spanTo — it's hard to remember which, since they're really the same underlying thing) do the Haskell people have a name for this? |
@dcsobral said: So I hope even more that this wasn't closed just because people are focusing on 2.8. |
@lindydonna said: |
Steven Bethard (bethard) said: This isn't the first time I've needed this either. I actually think takeTo is much more useful than takeWhile, since you can always get the takeWhile result from the takeTo result, but not vice versa. That said, I don't know how to address your concern that there are too many methods in the library. |
@dcsobral said (edited on Dec 30, 2011 3:10:46 PM UTC): def takeTo(p: A => Boolean): Repr = {
val (before, after) = this span p
before :+ after.head
}
def dropTo(p: A => Boolean): Repr = this dropWhile p tail
def spanTo(p: A => Boolean): Repr = {
val (before, after) = this span p
(before :+ after.head, after.tail)
} |
a newer, open ticket on this is https://github.com/scala/scala-dev/issues/417 |
In the past few months I have sometimes wanted a
takeTo
method, which would take all elements up to and including the first for which a predicate was true. Or, in other words, the following equivalency would be true:I haven't found easy way to simulate such method using the existing ones. I have either used
sliding
, with the inconvenients it presents, or simply went about my code in a completely different manner.So I ask for this method to be added. The name I propose is based on the
until
/to
distinction used for ranges.The text was updated successfully, but these errors were encountered: