I've been looking at what I can do with Enum
, Stream
and for
comprehensions and I'm struggling to reproduce left outer join behavior. I can implement a left outer join function with Enum.reduce
but if there is some way to do that with for
I'd rather use that.
I know python supports it, I've seen it here and here, and I suppose Elixir's comprehensions were inspired by python's. Can we do it in Elixir?
Suppose I have two lists that came from an external API or some json/xml file:
categories = [%{id: 1, name: "beverages"}, %{id: 2, name: "vegetables"}]
products = [%{name: "ice tea", category: 1}, %{name: "sake", category: 1}]
I want to left outer join them to get something like:
cat_product == [
%{category: "beverages", product: "ice tea"},
%{category: "beverages", product: "sake"},
%{category: "vegetables", product: "(No product)"}
]
And something like:
cat_products == [
%{name: "beverages", products: [list of products]}
%{name: "vegetables", products: []}
]