Thank you for reminding me this functional concept, I didn’t know there was lens libraries in Elixir, that’s interesting for managing nested structures.
About your request and including more features in general: I have thought about handling Ecto as well, but finally I think it would be better if typed_struct remains a tiny library. Users not using Ecto or a lense library don’t need code related to these features. It would be better if they were in different packages. What I can add in typed_struct however is some plugin system to build upon. This way, if you wanted to define lenses for the keys of a typed struct, you could do something like this:
defmoduleMyStructdouseTypedStruct# This would contain the define_lenses/? function.importLensPlugintypedstructdoplugin:define_lensesfield:name,String.t()field:age,integer()endend
I’ve thought of this API in 5 minutes, it could change but you get the idea. This way, users could define callbacks that would be called during the typed struct definition, accessing to its fields. I will open a separate issue for this plugin feature.