title: Is there an equivalent for map or fmap to replace while loops?
body: <p>Haskell replaces for loops over iteratable objects with <code>map :: (a -&gt; b) -&gt; [a] -&gt; [b]</code> or
  <code>fmap :: (a -&gt; b) -&gt; f a -&gt; f b</code>. (This question isn't limited to Haskell, I'm just using the syntax here.)</p>
  <p>Is there something similar that replaces a <em>while</em> loop, like</p>
  <p><code>wmap :: ([a] -&gt; b) -&gt; [a] -&gt; ([b] -&gt; Bool) -&gt; [b]</code>?</p>
  <p>This function returns a list of <code>b</code>.</p>
  <p>The first argument is a function that takes a list and computes a value that will end up in the list returned by <code>wmap</code> (so it's a very specific kind of while loop).</p>
  <p>The second argument is the list that we use as our starting point.</p>
  <p>The third argument is a function that evaluates the stoping criteria.</p>
  <p>And as a functor,</p>
  <p><code>wfmap :: (f a -&gt; b) -&gt; f a -&gt; (f b -&gt; Bool) -&gt; f b</code></p>
  <p>For example, a <a href="https://en.wikipedia.org/wiki/Jacobi_method" rel="nofollow noreferrer">Jacobi solver</a> would look like this (with <code>b</code> now the same type as <code>a</code>):</p>
  <p><code>jacobi :: ([a] -&gt; [a]) -&gt; [a] -&gt; ([a] -&gt; Bool) -&gt; [a]</code></p>
  <p>What I'm looking for isn't really pure. <code>wmap</code> could have values that mutate internally, but only exist inside the function. It also has nondeterministic runtime, if it terminates at all.</p>
  <p>In the case of a <a href="https://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method" rel="nofollow noreferrer">Gauss-Seidel solver</a>, there would be no return value, since the <code>[a]</code> would be modified in place.</p>
  <p>Something like this:</p>
  <p><code>gs :: ([a] -&gt; [a]) -&gt; [a] -&gt; ([a] -&gt; Bool) -&gt; ???</code></p>
  <ol>
  <li>Does <code>wmap</code> or <code>wfmap</code> exist as part of any language by default, and what is it called?</li>
  </ol>
  <p><strong>Answer 1</strong> (thanks to <a href="https://stackoverflow.com/users/1048572/bergi">Bergi</a>): Instead of the silly <code>wmap</code>/<code>wfmap</code> signature, we already have <a href="https://hackage.haskell.org/package/base-4.14.0.0/docs/Prelude.html#v:until" rel="nofollow noreferrer"><code>until</code></a>.</p>
  <ol start="2">
  <li>Does an in place version of <code>until</code> exist for things like <code>gs</code>?</li>
  </ol>