title: How do immutable methods work in lodash fp?
body: <p>I'd like to understand how the immutable methods of lodash/fp work.</p>
  <p>Do they deeply clone a collection before changing it or do they implement kind of a structural sharing between the two versions of the object?</p>
  <p>I have tried to understand it &quot;from the outside&quot; and I couldn't come to a clear conclusion.</p>
  <p>In the first case below, mutating an updated collection doesn't impact the original collection.</p>
  <p>However, in the second case, mutating an updated collection does impact the original collection.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var fp = _.noConflict();
  
  var data = { a: { c: {} } };
  var updatedData = fp.set(["a", "c", "d"], 5, data);
  updatedData.a.c.e = 9;
  console.log(updatedData.a.c.e, data.a.c.e);
  
  var data2 = { a: { c: [] } };
  var updatedData2 = fp.set(["a", "d"], 5, data2);
  updatedData2.a.c[0] = 9;
  console.log(updatedData2.a.c[0], data2.a.c[0]);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src='https://cdn.jsdelivr.net/g/lodash@4.17(lodash.min.js+lodash.fp.min.js)'&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I have also posted the question on <a href="https://github.com/lodash/lodash/issues/4989" rel="nofollow noreferrer">Lodash github</a>.</p>