GithubHelp home page GithubHelp logo

clj-commons / useful Goto Github PK

View Code? Open in Web Editor NEW
365.0 21.0 58.0 758 KB

Some Clojure functions we use all the time, and so can you.

License: Eclipse Public License 1.0

Shell 0.25% Clojure 99.75%

useful's Issues

Move away from sun.misc.Base64decoder

On Java 11 and 12-ea:

 java.lang.ClassNotFoundException: sun.misc.BASE64Decoder, compiling:(flatland/useful/compress.clj:1:1)

java.util.Base64 would be good, but it's only available on Java 8 onwards. Probably still the best choice, but would mean dropping support for Java 7 and down, at least for the flatland.compress namespace.

Transform ALL keys in map

Right now the map-keys function only maps the top keys, i.e:

(map-keys str {:a {:b "c"}})
=> {"a" {:b "c"}}

Can we consider adding something like map-all-keys, map-all-values, etc that will traverse a nested structure? The use case here could be transforming a clojurefied map into a formatted JSON object or vise versa for example.

(defn transform-keys
  "Recursively transforms all map keys in coll with t."
  [t coll]
  (let [f (fn [[k v]] [(t k) v])]
    (clojure.walk/postwalk (fn [x] (if (map? x) (into {} (map f x)) x)) coll)))

(transform-keys ->kebab-case-keyword {"oneTwo" 12 "threeFour" {"fiveSix" 56}})
=> {:three-four {:five-six 56}, :one-two 12}

OR

(defn transform-keys 
  "Recursively transforms all map keys in m with f."
  [f m]
  (letfn [(mapper [[k v]] [(f k) (if (map? v) (map-keys f v) v)])]
    (into {} (map mapper m))))

(transform-keys ->kebab-case-keyword {"oneTwo" 12 "threeFour" {"fiveSix" 56}})
=> {:three-four {:five-six 56}, :one-two 12}

ignoring-nils

((ignoring-nils +) nil nil) returns 0, but ((ignoring-nils +) nil nil nil) returns nil. Is this difference intentional? I figure they should both return 0.

Copyright holders

I am a Debian developer packaging Clojure and Leiningen. Leiningen2 depends on this project and I'd like to package it. Could you please display copyright holders (developers) for this work? project.clj is likely a good place to note that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.