I have an an object as
%{
shares: []
}
I want to add a struct %Cs{name: "Junaid1"}, %Cs{name: "Junaid2"} into the list through Enum.each or map, is that possible to do?
Okay for just more brief I am updating question again..
Enum.each(email_array, fn (email) ->
with {:found_user, sharee} <- ensure_user(email)
do
case CameraShare.create_share(camera, sharee, caller, params["rights"], params["message"]) do
{:ok, camera_share} ->
#Add camera_share to list
{:error, changeset} ->
#Add error to a list
end
else
{:not_found, email} ->
case CameraShareRequest.create_share_request(camera, email, caller, params["rights"], params["message"]) do
{:ok, camera_share_request} ->
#Add camera_share to list
{:error, changeset} ->
#Add error to list
end
end
end)
and then at the end of Enum.each.. there will be a map as
%{
shares: [all shares],
errors: [all errors]
}
where as each share is of type %CameraShare{__meta__: #Ecto.Schema.Metadata<:loaded, "camera_shares">}