-
Notifications
You must be signed in to change notification settings - Fork 18
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
Document lists.take-while
#22
Comments
Wouldn't |
No one knows about scheme :-) And "span" has no connotation of splitting a list into two related pieces; it sounds more like building a bridge or something. We already have Haskell (https://www.haskell.org/hoogle/?hoogle=takeWhile), Ocaml (http://batteries.forge.ocamlcore.org/doc.preview:batteries-beta1/html/api/List.html), .Net (https://msdn.microsoft.com/en-us/library/bb534804(v=vs.110).aspx), Clojure (https://clojuredocs.org/clojure.core/take-while), ReactiveX (http://reactivex.io/documentation/operators/takewhile.html) and plenty of others all call it take_while, but they're all dumb and don't return the back half of the list. So we're better ;-) |
What about Your example of Two common names in other programming languages:
|
I like this argument – I'm in favor of split-with
…On Mon, Aug 14, 2017 at 7:33 PM, sorawee ***@***.***> wrote:
What about split-with? (https://clojuredocs.org/clojure.core/split-with)
Your example of take helps the argument that I'm going to make actually.
We have take, drop, and split-at which operate on index. Traditionally,
take-while and drop-while should be like take and drop that operates on
predicate instead of index, so using the name take-while for the thing
that should be similar to split-at is really misleading and inconsistent.
Two common names in other programming languages:
- Haskell and Scheme use span (https://hackage.haskell.org/
package/base-4.10.0.0/docs/Data-List.html#g:11
<https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-List.html#g:11>)
for the predicate version of split-at, but I agree that span has no
connotation of splitting a list into two related pieces.
- split-with in Clojure seems really nice.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#22 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHUU2y4DKB2vFhjOpmQONSWGNlADm_sks5sYQNwgaJpZM4O3DM9>
.
|
I don't -- it doesn't tell me at all whether the split happens when the predicate goes from true to false, or vice versa. "Take while" to me at least connotes "while true" (as in, "get it while the getting's good") Honestly I don't care enough about this to really complain, but I think all these names are pretty lousy and take-while seemed the best of the bunch to me. |
For what it's worth, whenever I've written a solution to `rainfall` (which
needs to take all the elements until it hits the first zero), I've always
written it as `take-while` (with the predicate being that the values are
non-zero).
|
Once brownplt/pyret-lang#1134 lands, we'll have a new function
take-while
available, which takes a predicate and splits a list into a front and back part such that all the items in the front list pass the predicate, and the first item of the back list fails.The text was updated successfully, but these errors were encountered: