Last active
December 20, 2015 15:09
-
-
Save klmr/6152098 to your computer and use it in GitHub Desktop.
When not to use point-free style: Composed functions don’t always auto-vectorise well. As a consequence, we’re left with monsters such as this one. It might be worth investigating whether the function composition tools could be changed (transparently) to make auto-vectorisation more universal. In particular, the problem lies with `fapply`, which…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
capitalize <- | |
p(fapply, toupper %.% p(substring, 1, 1), p(substring, 2)) %|>% | |
p(lapply, p(paste, collapse = '')) %|>% unlist | |
# versus | |
capitalize <- function (str) paste(toupper(substring(str, 1, 1)), | |
substring(str, 2), sep = '') | |
# Usage (in both cases): | |
capitalize(c('abc', 'def')) # => 'Abc' 'Def' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment