title: Creating a composed functions with pure functions
body: <p>I am trying to get my head around both composed functions and pure functions.</p>
  
  <p>I have an object with a mixture of data. On some values I need to:</p>
  
  <ol>
  <li>remove the value's units </li>
  <li>parse string to integer </li>
  <li>Convert to value decimal</li>
  </ol>
  
  <p>I have written three functions attempting to make them pure in the sense that they only do one thing but strictly speaking, they are mutating state. I'm not sure how to avoid mutating state though and if this technically makes it not a pure function?</p>
  
  <p>My three "pure" functions are:</p>
  
  <pre><code>function parseValue(val) {
      return typeof val === 'number' ? val : parseInt(val)
  }
  
  function stripUnits(val) {
      return typeof val === 'string' ? val.match(/\d+/)[0] : val
  }
  
  function convertToDecimal(val) {
      return val / 100
  }
  </code></pre>
  
  <p>I am then trying to compose these functions into one function with the help of <a href="https://github.com/lodash/lodash/wiki/FP-Guide" rel="nofollow noreferrer">lodash</a> <code>compose()</code> </p>
  
  <pre><code>function prepValue(val) {
      return compose(stripUnits, parseValue, convertToDecimal)
  }
  </code></pre>
  
  <p>When I try run this <code>console.log("prepValue", prepValue(weather.current.temperature))</code> I get the following in the terminal:</p>
  
  <pre><code>prepValue function (){var n=arguments,e=n[0];if(o&amp;&amp;1==n.length&amp;&amp;of(e))return o.plant(e).value();for(var u=0,n=r?t[u].apply(this,n):e;++u&lt;r;)n=t[u].call(this,n);return n}
  </code></pre>
  
  <p>So the main things is, </p>
  
  <ol>
  <li>How can I make my three functions "pure" </li>
  <li>How can I compose these functions into 1</li>
  </ol>