![Avinder Bahra Profile](https://pbs.twimg.com/profile_images/1220970417667608576/pgyjBMnj_x96.jpg)
Avinder Bahra
@avinder42
Followers
153
Following
884
Statuses
230
FP and House Music enthusiast. Lead developer on ZIO DynamoDB.
England, United Kingdom
Joined April 2016
Looking forward to using Schema 2 optics in ZIO DynamoDB
The optics in the new ZIO Schema I am working on are "reflective optics" (a term I just made up, but it fits). This means that, in addition to letting you do get- & set-like things (like legacy optics), you can ALSO access the reified structure of the underlying types. This lets you use the optics in DSLs, like SQL, DynamoDB, or Cassandra. e.g.: selectFrom("foo").where(Person.age > 20) Interestingly, however, reflective optics beat legacy optics at their own game in one important way: killer error messages. Optic composition invariably introduces optionality in "getting". With almost all legacy optics, you learn that SOME value had an unexpected constructor, but you don't get any information on the error, leaving you to puzzle over why some update operation didn't work. With reflective optics, it should be possible to support brilliant error messages, along the lines of: "In Order.items[*].billingAddress.country, expected field billingAddress to be Some but found None." Boom! You know exactly how your expectation differed from reality when doing some targeted operation on a deeply nested structure. As a bonus, reflective optics are also eminently usable as "keys" in maps, because the data they contain is sufficient for disambiguation. This means another place where they will shine is in applications involving data-generic metadata. Currently, if you have a deeply nested structure like Order, there's no good type-safe, expression-oriented way to attach metadata to particular parts of its substructure--not without modifying it and adding slots for the metadata. For example, you might want to attach documentation, validation rules, or format hints. With reflective optics, you can now attach arbitrary metadata to arbitrary parts of a substructure. For example: val validatedCodec = orderCodec.validate((items)(billingAddress)(country))(CountryCodes.contains(_)) This is going to open up new applications for optics, as well as greatly simplify some tasks that were possible before, but only at great cost to ergonomics (using fixed point data and recursion schemes, zippers, etc.). In short, reflective optics aren't your grandpa's optics--they're way better! 😅
0
0
7
RT @jdegoes: The optics in the new ZIO Schema I am working on are "reflective optics" (a term I just made up, but it fits). This means tha…
0
6
0
RT @jdegoes: Now, as funny as I find this, there's obviously something useful to learn from this kind of feedback: That a working develope…
0
2
0
RT @etorreborre: I expand a bit on why we need a real programming language to configure our systems in my latest blog post:
0
4
0
RT @graninas: 20 years ago, I started using a shit programming language. The tooling was shit too. I thought, it’s fine, because you can a…
0
1
0
RT @graninas: Developers with a great short-term memory are the worst. They keep huge contexts in their heads and don't see the need to st…
0
4
0
@kitlangton finally got some time to try this - worked flawlessly with zio-schema in a zio-dynamodb example - awesome work!
0
0
1
@hmemcpy @zeddotdev Gonna sneak in a workout today in my home gym after roasting the vegetables
0
0
0
@ghostdogpr zio-schema has reified optics but that is quite a specialised use case, maybe not what you are after
1
0
1