Human friendly trim of a string
<p>I want to trim a string in a human friendly way.</p>

<pre><code>foobar="John Doe - CEO @ xyz"

def human_trim(input, length) do
  ...
end
</code></pre>

<p>When <code>human_trim(foobar, 10)</code> the output should be <code>John Doe</code>. <code>human_trim(foobar, 7)</code> should result in <code>John</code>. So splitting by space and than check what fits until the 10 characters are reached. The edge case would be a string with no spaces at all. Than it would have to cut at -3 and add '...' at the end.</p>

<p>I can figure out a way to solve this problem with a million of if/else. But I struggle to find a clean way which solves this recursively. Elixir style.</p>

<p>What is the cleanest way to solve this? </p>

<p>Bonus-Question: Is the cleanest also the most performant solution?</p>