Hey everyone. I’m trying to use my own struct (as a extension of map) in my code but I would really love to use the Methods from the Access behaviour. Is there an easy way to achieve this?
defmodule SemanticConcept do
defstruct [:text, :offset, :token_span, :resources]
Access is a behaviour, so you just need to implement the behaviour functions. They’re already implemented for a Map so you can just delegate to the map module.
defdelegate fetch(term, key), to: Map
defdelegate get(term, key, default), to: Map
defdelegate get_and_update(term, key, fun), to: Map
You can do it one line with this package I wrote: