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

Creating transformers ... "@@"?? #44

Open
shaunc opened this issue Apr 24, 2017 · 1 comment
Open

Creating transformers ... "@@"?? #44

shaunc opened this issue Apr 24, 2017 · 1 comment

Comments

@shaunc
Copy link

shaunc commented Apr 24, 2017

Does the use of "@@" in the protocol mean that in es6 code I should actually do something like the following to define a transformer?

const init = Symbol.for('transducer/init');
const result = Symbol.for('transducer/result');
const step = Symbol.for('transducer/step');
function MapTransformer() {
  return {
    [init]() { return xf[init](); }
    [result](res) { return xf[result](res); }
    [step](res, input) { return xf[step](res, f(input)); }
  };
}

I'm confused what the "@@" are supposed to represent as it doesn't look like you have es6 support -- I don't suppose the above is actually interoperable with the library. But isn't "@@" for "well-known symbols" in es6?

@seanpoulter
Copy link

seanpoulter commented Feb 11, 2018

isn't "@@" for "well-known symbols" in es6?

Yep. Have a look at the Symbols chapter of You Don't Know JS: ES 6 & Beyond. Here's a note from the Built-in Symbols section:

The specification uses the @@ prefix notation to refer to the built-in symbols, the most common ones being: @@iterator, @@toStringTag, @@toPrimitive.


That leads to the question, are a String and a Symbol equivalent? You can use the following block to spot check if they're the same. It looks to me like you'll need a PR to support Symbols before your code with Symbols.

Array.prototype['@@custom'] = 'from String';
console.log([]['@@custom']);
// > 'value'

const sym = Symbol.for('custom');
console.log([][sym]);
// > undefined

Array.prototype[sym] = 'from Symbol'
console.log([][sym]);
// > 'from Symbol'

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

2 participants