4 ms·
It's actually a very little function I wrote, based on `tee` Unix shell command: http://unixhelp.ed.ac.uk/CGI/man-cgi?tee http://unixhelp.ed.ac.uk/CGI/man-cgi?t
by klibertp 12y ago
It's actually a very little function I wrote, based on `tee` Unix shell command: http://unixhelp.ed.ac.uk/CGI/man-cgi?tee http://unixhelp.ed.ac.uk/CGI/man-cgi?tee
It looks like this:
tee = (func, val) --> func(val); val
which could be equivalently written as:
tee = (func) -> (val) -> func(val); val
In other words it's an identity function which additionally executes some other function for side-effects. In the shell the `tee` command always writes to the file, while my version can execute any side-effect, but I think my version is just a generalization of the standard Unix command and so I named it like this.
I'm sure this function has its own, formal name, with the word "monad" or "combinator" (maybe K combinator?) in it, but I wasn't patient enough to research it :)
`thenResolve` is a standard method on a promise object implemented by the Q library (https://github.com/kriskowal/q/wiki/API-Reference#promisethenresolvevalue https://github.com/kriskowal/q/wiki/API-Reference#promisethe...) I used, it's equivalent to
.then () -> accum
In other words, `thenResolve` appends a success callback which discards previous value and always returns another value.
Once again, take a look at the full source at http://klibert.pl/walkfiles.html http://klibert.pl/walkfiles.html - I'm going to update it with a full explanation of what's going on, but even right now it's only 90 lines with including comments, and should be a good example of main LS strengths. I'm probably going to write another example which makes use of even more (and more advanced) LS features when I'm done with explaining this one.
- agumonkey 12y agoActually my reflection started with using tee and pipes in bash, having a desire to sync/join on the multiple paths created by tees. Interesting job that you did.