FP now and today? #2530
Unanswered
samuelcolburn
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I guess this is one part question and one part potentially suggestion.
Question: how do you use 'now' and 'today' values with the fp functions, such that you always get the current time, especially in a point-free style with other functional libraries like lodash/fp or ramda?
Because the curried functions expect a Date object, I find myself writing fairly dys-functional (see what I did there) wrappers to stub current date values in order to call them with a current time, like this:
Even I write a simple stub function like:
I still have to call it during the function definition, and get a static now value:
So has anyone else run into similar issues, and gotten around it in a 'nicer' or 'more functional' way than I'm thinking of? Which leads to the suggestion part: I think it would be nice to:
/fp
library just for consistency, possibly also with the alias 'stubToday` since it's a common term.stubNow
functionformatRelativeToNow
,formatDistanceToNow
, etc. In other words, I want to be able to write a function like this:edit: added example to suggestion.
Beta Was this translation helpful? Give feedback.
All reactions