Bug 15923 - add TakeWhile function to funprog (patch included)
Summary: add TakeWhile function to funprog (patch included)
Status: REOPENED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R-devel (trunk)
Hardware: Other All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-08-06 15:33 UTC by Matthias C. M. Troffaes
Modified: 2014-08-07 08:10 UTC (History)
1 user (show)

See Also:


Attachments
TakeWhile patch against trunk r66309 (4.58 KB, patch)
2014-08-06 15:33 UTC, Matthias C. M. Troffaes
Details | Diff
TakeWhile patch against trunk r66311 with additional right = TRUE support (5.48 KB, patch)
2014-08-07 08:09 UTC, Matthias C. M. Troffaes
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias C. M. Troffaes 2014-08-06 15:33:36 UTC
Created attachment 1639 [details]
TakeWhile patch against trunk r66309

R's functional programming facilities are great. This patch adds a TakeWhile function, modelled after Haskell's takeWhile and python's itertools.takewhile, useful in situations where you want the largest prefix of a list or vector satisfying a predicate. There are probably other useful candidates for adding (e.g. DropWhile) but this seems like a good start.

Patch attached. Includes documentation and regression tests.
Comment 1 Duncan Murdoch 2014-08-06 17:25:26 UTC
This bug list is for bugs/changes to base R.  Send suggestions for contributed packages to the package maintainer.  Since funprog is not a CRAN package, I don't know who that is, but the DESCRIPTION file should tell you.
Comment 2 Duncan Murdoch 2014-08-06 18:39:55 UTC
Whoops, misunderstood that.  Someone who is familiar with funprog.R should take a look.
Comment 3 Matthias C. M. Troffaes 2014-08-07 08:09:52 UTC
Created attachment 1640 [details]
TakeWhile patch against trunk r66311 with additional right = TRUE support
Comment 4 Matthias C. M. Troffaes 2014-08-07 08:10:44 UTC
Thanks for the response, and sorry for confusing you!

A colleague (Paul Fink) suggested to support right = TRUE as well. Attached is a more extensive patch implementing this as well, including further regression tests and documentation as usual.

(I guess it could make sense to put this function - and possibly others - into a separate package on CRAN, however it seems that R encourages a functional programming style, hence at least in my subjective view it makes more sense to have it right in base. As far as it may serve as a guidance, note that both Python and Haskell have it in their standard library.)