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

Create Mnemonix.Conn struct #9

Open
christhekeele opened this issue Oct 31, 2016 · 0 comments
Open

Create Mnemonix.Conn struct #9

christhekeele opened this issue Oct 31, 2016 · 0 comments

Comments

@christhekeele
Copy link
Owner

Rather than returning the raw t:GenServer.server/0 for consumption in the Mnemonix API, we could instead wrap that value in a Mnemonix.Conn struct.

There are several cool things we could do with a struct instead:

  • Implement the Access protocol to support Kernel.put_in and ilk
  • Implement the Collectible protocol to co-erce data into a new store via Enum.into/2
    • This gives us a better Mnemonix.new
    • This gives us analogs for:
      • Map.from_struct/1
      • Map.merge/3..4
      • Map.split/2
      • Map.take/2
  • Implement the Enumerable protocol to iterate over store contents
    • This gives us analogs for:
      • Map.keys/1
      • Map.values/1
      • Map.to_list/1
    • Stores would have to be able to opt out
  • With both of the above, only Map.equal/2 would have no analog
    • Until the inevitable Comperable protocol
  • Convert the Mnemonix API into a protocol and implement it for Mnemonix.Conn
    • Could also implement it for Map real parity with in-mem data stores
    • Could grant other structs access to the API in custom ways that don't mandate the GenServer wrapper

Of course, there are some issues:

  • It's another layer of indirection
  • Need to consider how to create structs for the same store in different processes consistently
  • Probably would expand the initialization API beyond just start_link
  • The protocol thing is really just kind of silly

Merits some more experimentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant