question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optic doesn't support Symbol.

See original GitHub issue

Well, Optic is support String, Array …etc However, the ES6 new type Symbol is mostly support by modern browser and Node.js. But, if we create a new Optic like this:

[
  Symbol(),
  'string'
]

The error is throw.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
polytypiccommented, Apr 8, 2018

Ah… Good question. xi2yF spells out the signature of the parameter: it is a function that maps the value under scrutiny x and its index i to the resulting value y in functor F.

1reaction
polytypiccommented, May 7, 2018

Yes, currently Partial Lenses do not support symbols and in non-production mode the library raises an exception as seen here.

I’m not opposed to supporting symbols, but I’m not entirely sure what the best way to support them would be. Ramda, for example, does not currently support symbols. It seems that the use case of symbols is to avoid name clashes. Even JavaScript itself seems rather undecided on how symbol properties should be treated: object spread ignores them, while Object.assign copies them as seen here. Object spread and Object.assign copy symbols as seen here.

I did some quick tests and it seems that copying symbol properties (using builtin Object.assign or Object.getOwnPropertySymbols) would cause something like a 2x performance hit in latest Node for property lenses. Note that I mean this in the sense of supporting the possibility of having symbol properties—I actually tested this on objects that did not have symbol properties, so there was no extra cost of actually copying more. Hopefully future JS engines will have faster implementations of Object.assign and then supporting symbol properties could be done without taking a performance hit.

For the above two reasons, namely

  • that there currently does not seem to be a consensus on what the best way to support them is (copy or not copy), and
  • that copying them (it seems) could could cause a 2x performance hit,

I’d rather not enhance the default property lenses in Partial Lenses to support symbol properties at this point. The above concerns may change in the future (IOW, a consensus may be reached and copying symbol properties might get significantly faster) at which point this could be reconsidered.

Note that you can always write custom optics for accessing objects with symbol properties. Here is a simple example using L.lens and here is a version that also provides the symbol or string as the index (Oops: Fixed!). At the moment this is what I’d recommend if you need to access objects with symbol properties.

Also, it might be useful to add the above sym lens to the library. Possibly with a better name? Name suggestions and/or PR is welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optical Drives (CD/DVD) Icon Not Showing in My Computer
Hi, Optical Drivers (CD/DVD) icon not showing in my computer window. Many times Windows users face strange problem when they can't see the ......
Read more >
Optical Disk Drive is not recognized in Microsoft Windows or ...
The instructions below help you diagnose and resolve issues if your CD, DVD, or Blu-Ray drive is not being recognized in Microsoft Windows ......
Read more >
Material Symbols guide | Google Fonts
Symbols are available in three styles and four adjustable variable font axes (fill, weight, grade, and optical size).
Read more >
Creating custom symbol images for your app - Apple Developer
Create, organize, and annotate symbol images using SF Symbols.
Read more >
Infant Optics DXR-8 Troubleshooting - iFixit
If the battery is plugged in correctly and charged, but the Monitor is still not working, the battery is faulty. Consider purchasing a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found