I recently changed some of the internals of an app, moving from Maps to Structs. Where some of my pipelines relied on accessing particular keys in a map, moving to Structs obviously breaks all these
(UndefinedFunctionError) function Foo.fetch/2 is undefined (Foo does not implement the Access behaviour
To make a long story short: what is the preferred way of accessing struct keys in a pipeline, without having to implement anything (like access behaviour) on the struct?
%{“foo” => “bar”}
|> Map.get(“foo”)
# => “bar”
%Foo{foo: “bar”}
|> ??? # get the ‘foo’ key somehow?
# => “bar”
I feel a bit silly asking for what I think should be fairly basic, but can’t find the answer…
Still works. The major difference is that structs don’t by default implement the entirety of the Access behaviour. For example foo[:foo] wouldn’t work.