Can you pattern match a non empty array in elixir? : <p>I have a <code>User</code> model with a <code>has_many</code> relationship to <code>other_model</code>.
I have a function <code>Search</code> that searches the internet. What I would like to do is search the internet only if the <code>has_many</code> relationship is not an empty array. </p>

<p>So I'm wondering if I can pattern match against a non-empty array? As you can see below, the extra <code>Search</code> results in nested branch and hence I use the <code>with</code> statement and am hoping for a clean solution. </p>

<pre><code>query = from a in Model, where: a.id == ^id, preload: [:some_associations]

with %{some_associations: some_associations} &lt;- Repo.one(query),
      {:ok, some_results} &lt;- Search.call(keywords, 1) do
            do_something_with(some_associations, some_results)
else
    nil -&gt; IO.puts "query found nothing"
    {:error, reason} -&gt; IO.puts "Search or query returned error with reason #{reason}"
end
</code></pre>
