I think it would be really helpful to implement tap so you can do debugging/printing in the middle of a composition.
I agree that tap is very useful when debugging, but I don't think Sanctuary should provide functions which encourage effectful code. It seems reasonable to me to add a one-line definition near the top of a file while debugging, and to delete the definition once it is no longer being used. One could even save the following snippet in such a way that one's text editor will insert it on demand:
// tap :: (a -> b) -> a -> a
const tap = f => x => (f (x), x);
Well I’m pretty sure that most users would find annoying having to do that
at every point and will most certainly not create a new function at the top
of the file every time. Nor would they like to insert an import statement
if they’re importing the entire namespace from Sanctuary, because both
cases would require you to move away from the code you’re looking at. What
it’s most likely to happen is they’ll add an arrow function and forget the
return value.
IMHO usability should be a major concert and I think that was the main
reasoning behind RxJS and ramda’s implementation.
As I might have mentioned in a related issue, it’s hard to transition to
Best Regards,
Adrian Perez
https://adrianperez.codes
On March 13, 2018 at 8:55:48 AM, David Chambers ([email protected])
wrote:
I agree that tap is very useful when debugging, but I don't think
Sanctuary should provide functions which encourage effectful code. It seems
reasonable to me to add a one-line definition near the top of a file while
debugging, and to delete the definition once it is no longer being used.
One could even save the following snippet in such a way that one's text
editor will insert it on demand:// tap :: (a -> b) -> a -> aconst tap = f => x => (f (x), x);
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/sanctuary-js/sanctuary/issues/504#issuecomment-372577282,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAIIvMdZTuj_beiR5uvvxoEdm0M6F-JNks5td3uDgaJpZM4SntAY
.
One option is to add the function to S yourself:
// index.js
const S = require ('sanctuary');
const foo = require ('./foo');
S.tap = f => x => (f (x), x);
...
// foo.js
const S = require ('sanctuary');
const asdf = S.pipe ([
...
S.tap (console.log), // works because shared module has been mutated
...
]);
Are we seriously encouraging monkey-patching libraries? 😂
It's fine if you don't want to add it, as I'm probably I'm the only one suggesting it. You can close this, but feel free to revisit if anyone else screams ¯_(ツ)_/¯
:joy:
You can close this, but feel free to revisit if anyone else screams
Okay. Good idea.
I don't think Sanctuary should provide functions which encourage effectful code.
I agree.
I use the following piece of code x => console.log(x) || x instead of tap (console.log). It doesn't take many extra character strokes, causes my linter to flag this line due to console use, it's globally available so I don't have to remove unused imports, and the console.log(x) ||-part can be safely inserted before any expression - so I can use it outside the context of a functional pipeline too, without having to remember different ways of debugging.
If you prefer debugging with tap, there are dedicated libraries for this case. I remember coming across some in the past, and a short github search turned up a few:
The x => console.log(x) || x trick is handy, Aldwin. :)
Most helpful comment
I agree.
I use the following piece of code
x => console.log(x) || xinstead oftap (console.log). It doesn't take many extra character strokes, causes my linter to flag this line due toconsoleuse, it's globally available so I don't have to remove unused imports, and theconsole.log(x) ||-part can be safely inserted before any expression - so I can use it outside the context of a functional pipeline too, without having to remember different ways of debugging.If you prefer debugging with
tap, there are dedicated libraries for this case. I remember coming across some in the past, and a short github search turned up a few: