In Elixir how do you initialize a struct with a map variable -


i know possible create struct via %user{ email: 'blah@blah.com' }. if had variable params = %{email: 'blah@blah.com'} there way create struct using variable eg, %user{ params }.

this gives error, wondering if can explode or other way?

you should use struct/2 function. docs:

defmodule user   defstruct name: "john" end  struct(user) #=> %user{name: "john"}  opts = [name: "meg"] user = struct(user, opts) #=> %user{name: "meg"}  struct(user, unknown: "value") #=> %user{name: "meg"} 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -