Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request : integeration with a lens library #8

Closed
fcabouat opened this issue Oct 29, 2018 · 2 comments
Closed

Feature request : integeration with a lens library #8

fcabouat opened this issue Oct 29, 2018 · 2 comments
Assignees
Labels
feature

Comments

@fcabouat
Copy link

@fcabouat fcabouat commented Oct 29, 2018

Hi,

Did you consider providing some integration with one or more lens libraries ?

https://github.com/tpoulsen/focus → they already have a "deflens" macro, that defines struct and lenses at the same time
https://github.com/obrok/lens → seems more feature complete

Thanx for your library !

@ejpcmac
Copy link
Owner

@ejpcmac ejpcmac commented Oct 30, 2018

Hello @fcabouat!

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:

defmodule MyStruct do
  use TypedStruct

  # This would contain the define_lenses/? function.
  import LensPlugin

  typedstruct do
    plugin :define_lenses

    field :name, String.t()
    field :age, integer()
  end
end

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.

@ejpcmac ejpcmac added the feature label Oct 30, 2018
@ejpcmac ejpcmac mentioned this issue Oct 30, 2018
8 tasks
@ejpcmac ejpcmac self-assigned this Apr 22, 2019
@ejpcmac
Copy link
Owner

@ejpcmac ejpcmac commented May 31, 2020

You can now use TypedStruct 0.2.0 with typed_struct_lens.

@ejpcmac ejpcmac closed this as completed May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature
Projects
None yet
Development

No branches or pull requests

2 participants