0

This question might not have any relation to daily challenges, but thinking about relations between the purpose of the Symbol itself and Iterable Protocol.

The symbol has its concrete responsibility but why is Iterable Protocol encapsulated inside it, could not understand.

Why Iterable protocol is not provided as external, independent functionality?

  • 1
    The symbol is part of the protocol. It's really unclear what you mean. The "Iterator protocol" is nothing tangible, it is not stored, it is not encapsulated. – Bergi Sep 23 '21 at 20:09
  • Can you explain what you mean by "*external, independent functionality*"? How would you envision the protocol to work, what changes would you make? – Bergi Sep 23 '21 at 20:09
  • For example Generators in JS stands on Iterator protocol or pattern. The same pattern is provided through Symbol.iterator. Symbols themselves are different things, they provide an opportunity to declare very unique primitives. but on the other hand, you can use its extension like: const regularArray = [ 1, 2, 3 ]; const iterableArray = regularArray[ Symbol.iterator ](); iterableArray.next(); – Alexander Gharibashvili Sep 23 '21 at 20:15
  • Are you confusing the iterator protocol with the iterable protocol? See https://stackoverflow.com/q/59458257/1048572 https://stackoverflow.com/q/50974411/1048572 https://stackoverflow.com/q/36543585/1048572 – Bergi Sep 23 '21 at 20:19

0 Answers0