title: return first {Key, Value} from Map where Predicate is true
body: <p>The more formal definition of problem is  </p>
  
  <blockquote>
    <p>Write a function map_search_pred(Map, Pred) that returns the first
    element {Key,Value} in the map for which Pred(Key, Value) is true.</p>
  </blockquote>
  
  <p>My attempt, looks like  </p>
  
  <pre><code>map_search_pred(Map, Pred)  -&gt;
    M = [{Key, Value} || {Key, Value} &lt;- maps:to_list(Map), Pred(Key, Value) =:= true],
    case length(M) of
      0 -&gt; {};
      _ -&gt; lists:nth(1, M)
    end.
  </code></pre>
  
  <p>When I run this, I get correct answer  </p>
  
  <pre><code>1&gt; lib_misc:map_search_pred(#{}, fun(X, Y) -&gt; X =:= Y end).
  {}
  2&gt; lib_misc:map_search_pred(#{1 =&gt; 1, 2 =&gt; 2}, fun(X, Y) -&gt; X =:= Y end).
  {1,1}
  3&gt; lib_misc:map_search_pred(#{1 =&gt; 1, 2 =&gt; 3}, fun(X, Y) -&gt; X =:= Y end).
  {1,1}
  4&gt; lib_misc:map_search_pred(#{1 =&gt; 2, 2 =&gt; 2}, fun(X, Y) -&gt; X =:= Y end).
  {2,2}
  5&gt;   
  </code></pre>
  
  <p><strong>Problem?</strong><br>
  The problem is efficiency.<br>
  It uses list comprehension and runs for all the elements in the list. The better solution would be to return after the first match.  </p>
  
  <p>As a beginner to language, I do not know a better idiomatic way to solve this, so looking for better ideas and suggestions</p>