Search Results

Search found 2 results on 1 pages for 'zcaudate'.

Page 1/1 | 1 

  • is this a simple monad example?

    - by zcaudate
    This is my attempt to grok monadic functions after watching http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-Dont-fear-the-Monads. h uses bind to compose together two arbitrary functions f and g. What is the unit operator in this case? ;; f :: int - [str] ;; g :: str = [keyword] ;; bind :: [str] - (str - [keyword]) - [keyword] ;; h :: int - [keyword] (defn f [v] (map str (range v))) (defn g [s] (map keyword (repeat 4 s))) (defn bind [l f] (flatten (map f l))) (f 8) ;; = (0 1 2 3 4 5 6 7) (g "s") ;; = (:s :s :s :s) (defn h [v] (bind (f v) g)) (h 9) ;; = (:0 :0 :0 :0 :1 :1 :1 :1 :2 :2 :2 :2 :3 :3 :3 :3 :4 :4 :4 :4 :5 :5 :5 :5)

    Read the article

  • function to efficiently check a change of value in a nested hashmap

    - by zcaudate
    the motivation is for checking what has changed in a deeply nest map, kind of like a reverse of update-in. This is a simple example: (def p1 {:a {:a1 :1 :a2 :2} :b {:b1 :1 :b2 :2}}) (def p2 (update-in p1 [:a :a1] (constantly :updated)) ;; => {:a {:a1 :updated :a2 :2} ;; :b {:b1 :1 :b2 :2}} (what-changed? p1 p2) ;; => {:keys [:a :a1] :value :updated) (what-changed? p2 p1) ;; => {:keys [:a :a1] :value :2) I'm hoping that because clojure maps are persistent data-structures, there may be a smart algorithm to figure this out by looking at the underlying structure as opposed to walking through the nested maps and comparing the difference.

    Read the article

1