Closed jnolis closed 4 years ago
Do you think you can create an example to make this more concrete and inspire discussion?
Sure! What about the ol' trusty FizzBuzz, where I wanted to return a list that had both characters and numbers in it?
1:100 %>%
map_case_when(
.x %% 15 == 0 ~ "Fizzbuzz"
.x %% 3 == 0 ~ "Fizz",
.x %% 5 == 0 ~ "Buzz",
TRUE ~ .x
)
I wonder if case_when()
, when powered by vctrs, should be able to take the common type of all of the 100 results of this operation and return that. In this case since it is a mix of character/integer it would just return a list
(This smells like a use case for vec_simplify()
)
Thanks for the suggestion! Since case_when()
is all about vectorised iteration, and map()
is the opposite, it doesn't seem like a good fit.
Given that there is now a map with if_else functionality, would it make sense for there to exist a map_case_when?
The case_when functionality is extremely useful for avoiding nesting if_elses, so it seems like it could be useful for maps too. That seems like it could be overengineering though, I am not sure.