title: Elixir - Cannot invoke remote function inside match
body: <p>I'm working through a practice exercise on exercism and can't figure out why I'm getting the following error: </p>
  
  <pre><code>(CompileError) anagram.exs:19: cannot invoke remote function String.codepoints/1 inside match
  (stdlib) lists.erl:1353: :lists.mapfoldl/3
  (stdlib) lists.erl:1353: :lists.mapfoldl/3
  </code></pre>
  
  <p>I guess I'm not understanding pattern matching as well as I thought because I don't quite understand how I'm trying to call a remote function inside a match. Here are a couple examples of the test suite for context: </p>
  
  <pre><code>defmodule AnagramTest do
    use ExUnit.Case
  
  test "no matches" do
    matches = Anagram.match "diaper", ["hello", "world", "zombies", "pants"]
    assert matches == []
  end
  
  test "detect simple anagram" do
    matches = Anagram.match "ant", ["tan", "stand", "at"]
    assert matches == ["tan"]
  end
  </code></pre>
  
  <p>Here's my code: </p>
  
  <pre><code>defmodule Anagram do
    @doc """
    Returns all candidates that are anagrams of, but not equal to, 'base'.
    """
    @spec match(String.t, [String.t]) :: [String.t]
    def match(base, candidates) do
      base
      |&gt; String.codepoints
      |&gt; Enum.sort
      |&gt; scan_for_matches(candidates)
    end
  
    defp scan_for_matches(base, candidates) do
      Enum.scan candidates, [], &amp;(if analyze(&amp;1, base), do: &amp;2 ++ &amp;1)
    end
  
    defp analyze(candidate, base) do
      candidate
      |&gt; String.codepoints
      |&gt; Enum.sort
      |&gt; match?(base)
    end
  
    defp match?(candidate, base) do
      candidate == base
    end
  end
  </code></pre>
  
  <p>Am I not just passing variables through to the <code>analyze/2</code> function so that it ultimately returns a <code>boolean</code>? I appreciate any insight. </p>