Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active September 11, 2023 14:24
Show Gist options
  • Save borkdude/b16118aa12af1dac3e487612a7936aad to your computer and use it in GitHub Desktop.
Save borkdude/b16118aa12af1dac3e487612a7936aad to your computer and use it in GitHub Desktop.
partial.md

Here's a list of things I collected a conversation on partial. Personally I think using partial almost never has a benefit, while there are some downsides to using it. There are exceptional cases where partial has a benefit, e.g. if you want to "wrap" a multi-arity function or a function with an unknown amount of arguments.

Some reasons not to use partial:

*) For example, a function I recently encountered in a codebase. Personally I find comp and partial overused here and the usage of anonymous functions would improve understandability.

   (defn process-blocks [viewers {:as doc :keys [ns]}]
     (-> doc
         (update :blocks (partial into [] (comp (mapcat (partial with-block-viewer doc))
                                                (map (comp process-wrapped-value
                                                           apply-viewers*
                                                           (partial ensure-wrapped-with-viewers viewers))))))
         (select-keys [:blocks :toc :title])
         (cond-> ns (assoc :scope (datafy-scope ns)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment