← Back to context

Comment by latexr

2 months ago

The point here isn’t a specific library. It’s not even one specific language or runtime. No one is talking about literally five functions. Let’s not be pedantic and lose sight of the major point.

I get that, but if you’ve ever tried to extract a single utility function from lodash, you know that it may not be as simple as copy-pasting a single function.

  • If you are going to be that specific, then it would be good to post an example. If I remember correctly, lodash has some functions, that would be table stakes in functional languages, or easily built in functional languages. If such a function is difficult to extract, then it might be a good candidate to write in JS itself, which does have some of the typical tools, like map, reduce, and things like compose are easy to write oneself and part of every FP beginner tutorial. If such a function is difficult to extract, then perhaps lodash's design is not all that great. Maybe one could also copy them from elsewhere, where the code is more modular.

    But again, if the discussion is going to be that specific, then you would need to provide actual examples, so that we could judge, whether we would implement that ourselves or it would be difficult to do so. Note, that often it is also not required for ones use-case, to have a 100% matching behavior either. The goal is not to duplicate lodash. The purpose of the extracted or reimplemented function would still be ones own project, where the job of that function might be much more limited.

    • Let’s start with something simple, like difference().

      https://github.com/lodash/lodash/blob/main/dist/lodash.js#L7...

      So you also need to copy isArrayLikeObject, baseDifference and baseFlatten.

      For baseDifference, you also need to copy arrayMap and baseUnary.

      For baseFlatten, you also need to copy arrayPush.

      For isArrayLikeObject, you also need to copy isArrayLike and isObjectLike.

      For isArrayLike, you also need to copy isLength and isFunction.

      For isFunction, you also need to copy isObject and baseGetTag.

      For baseGetTag, you also need to copy getRawTag and objectToString.

      I don’t have time to dig any deeper, just use tree-shaking ffs.

      2 replies →