When creating a library which accepts transducers, it is useful to warn the users, if they mixed up the arguments. For example in
function createChannel(transducer = null) {}
it would be great if createChannel can (runtime) assert that it got the transducer and not e.g. string. For this purpose, .type attribute attached to transducer fn with value such as 'transducers-js' could be used. Another possibility is to add .@@__is_transducer__@@ attribute set to true (idea copied from https://github.com/facebook/immutable-js/blob/master/src/Iterable.js#L38)
Currently transducers are functions. This means we can distinguish them from strings, numbers and objects, but still, there is a lot of other functions that can be easily mixed up with transducers.
Finally, if someone wants to implement transducer protocol by themselves, they can assign the .type manually. This is however rather rare scenario.
When creating a library which accepts transducers, it is useful to warn the users, if they mixed up the arguments. For example in
it would be great if
createChannel
can (runtime) assert that it got the transducer and not e.g. string. For this purpose,.type
attribute attached to transducer fn with value such as 'transducers-js' could be used. Another possibility is to add.@@__is_transducer__@@
attribute set to true (idea copied from https://github.com/facebook/immutable-js/blob/master/src/Iterable.js#L38)Currently transducers are functions. This means we can distinguish them from strings, numbers and objects, but still, there is a lot of other functions that can be easily mixed up with transducers.
Finally, if someone wants to implement transducer protocol by themselves, they can assign the
.type
manually. This is however rather rare scenario.