dmm: (dynosaur)
Dataflow matrix machines (by Anhinga anhinga) ([personal profile] dmm) wrote2016-09-25 11:51 pm

writing Clojure snippets

(defn rec-map-mult [scalar rec-map-of-ns]
  (if (map? rec-map-of-ns)
      (into {}
            (map #(vector (first %1)
                          (rec-map-mult scalar (second %1))
                  )
                 rec-map-of-ns
            )
      )
      (if (number? rec-map-of-ns)
          (* scalar rec-map-of-ns)
          0
      )
  )
)

user=> (rec-map-mult  3 { :a 3 :b {:c 7 :d 9} })
{:a 9, :b {:c 21, :d 27}}

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting