Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Add .type field to transducers #37

Open
tomaskulich opened this issue Nov 19, 2016 · 0 comments
Open

Add .type field to transducers #37

tomaskulich opened this issue Nov 19, 2016 · 0 comments

Comments

@tomaskulich
Copy link

tomaskulich commented Nov 19, 2016

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant