egnha / nofrills Goto Github PK
View Code? Open in Web Editor NEWLow-cost anonymous functions
License: Other
Low-cost anonymous functions
License: Other
Test breakages are spurious, but need to be fixed to maintain good standing on CRAN.
E.g., eliminate functions that assume that quosures are formulas (an implementation detail, subject to change).
Because this is what print.default()
displays, which may diverge from rlang::as_closure()
. Affects partial()
.
Meaning, partial()
should be operationally idempotent.
For instance, partial(partial(f, x = 1), y = 2)
and partial(f, x = 1, y = 2)
should have the same run-time characteristics. Ideally, they should be implemented as the same function.
Given a good-enough partial()
, curry()
seems to add little value, given how tricky it is to implement it with the ”right” semantics, quasiquotation support and acceptable performance:
partial()
does)foo(a)(b)
and foo(a, b)
—in view of arguments with default values and the first two pointsSelf-explanatory, more concise.
Composition should produce an “optional type”: it should always be either NULL
or a function of class CompositeFunction
, even for a single function. This is required in order for generic methods to work predictably, e.g., as.list()
.
Current flatten_fns()
is clumsy.
Use expr_print()
, expr_deparse()
.
Would be nice to include illustrative "case studies" (e.g., serializers, k-means, ad hoc analyses).
nofrills as a toolbox of essential functional operators (lambda, composition, partial).
E.g., abs %>>>% log(bse = 2)
should raise error.
CI for Windows builds
Derive from printing of partial application (#22).
E.g., fn_interp.logical()
.
curry()
should directly call the original function on partialized arguments.
Unlike purrr::partial()
, this should enable unquoting and splicing of arguments.
API is simpler, and more intuitive, when the composition order is consistently inner to outer.
Classical currying is not very R. Relax curry()
to be variadically callable.
Cf. #14
Currently, it is somewhat noisy.
It is slow, because base R has no (public) facility for reusing compiled regular expressions. (Relying on a package like ore is infeasible, since I want to avoid additional dependencies.) In particular, is_bare_dot_names()
should be subsumed by a much cheaper predicate, e.g., a pre-computed, logical-vector attribute.
They are non-essential.
So that `[`
methods are properly scoped.
... for there is a canonical choice for the function argument.
... as a matter of efficiency.
Modify srcref
?
Subsetters, conversions, etc.
For instance, the printing of partial application is mildly complicated. Perhaps it should be tested.
With tidy evaluation, ..lazy
toggle is superfluous.
The selection boolean vector—the filter—should be exactly as long as the vector to be filtered. By default, R recycles filters. Since this is typically unintended, interpret a length mismatch as a bug. Disallow it at runtime.
Unquoting operators UQ()
, UQS()
, UQE()
will be (softly) deprecated in rlang 0.2.0, but their bang-operator aliases shall remain.
So that it is clear what is closure data and what is not.
Implicit partialization and “dot” functions à la magrittr:
readLines %>>>% gsub(" ", "", .)
abs %>>>% {. + 1} %>>>% log
Unquote to preempt the default behavior:
inc <- 1
abs %>>>% {. + !!inc} %>>>% log
(!!safely(f)) %>>>% {paste(.$result, collapse = "")}
sprint("%s", .) %>>>% paste(collapse = "")
rlang's quasiquotation API is more or less stable, but the rest of rlang is not. Until it is, restrict its use to the following: https://github.com/r-lib/usethis/blob/master/inst/templates/tidy-eval.R
For instance
curry(fn(x, y, z ~ x + y + z))
should yield
fn(x ~ !! fn(y ~ !! fn(z ~ x + y + z)))
(This can be accomplished with reduction.)
This would be useful for creating constant functions or functions with side effects (qua commands).
Hey Eugene, I was wondering (out of sheer curiosity) if it is possible to implement Javascript's syntax for anonymous function in R and stumbled upon your package. It seems to be very cool!
Do you think it is viable to implement something like this in R?
(x, y) => {
x + y
}
Because composition should be a monoid homomorphism—NULL
is dropped from concatenations, consequently it maps to the identity function under composition.
Variation of fn() that does not support quasiquotation.
E.g., partial(function(x) x, !!!list(0))
should match 0
to x
.
With regards to partial application and currying, there are two views on ...
: 1) as a special kind of indecomposible type—how the interpreter sees it; 2) as an infinite product type (of mode any
)—how the user sees it.
Choose the one that is compatible with typical use cases.
So that, e.g., `[[`(, 1) %>>>% sample(size = 3)
means “sample 3 from the first component.”
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.