<< Back to previous view

[ALGOM-4] algo.monad state-m fetch-val bug and efficiency issue Created: 08/Sep/12  Updated: 05/Feb/14  Resolved: 05/Feb/14

Status: Closed
Project: algo.monads
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Sacha De Vos Assignee: Konrad Hinsen
Resolution: Completed Votes: 0
Labels: bug, performance
Environment:

irrelevant



 Description   

;; the bug

(defn fetch-val
"Return a state-monad function that assumes the state to be a map and
returns the value corresponding to the given key. The state is not modified."
[key]
(domonad state-m
[s (fetch-state)]
(key s))) ;; does not work for integer or string keys

;; I propose replacing it with (get s key)

;; the efficiency issue :
;;
;; domonad with monad parameter binds all the monad functions,
;; looking these up in the state-m map on each call
;;
;; solution :

(defn fetch-val
"Return a state-monad function that assumes the state to be a map and
returns the value corresponding to the given key. The state is not modified."
[key]
(fn [s]
[(get s key) s]))

;; - we avoid the monad map lookups
;; - coding style brought up to par with the rest of state-m functions



 Comments   
Comment by Konrad Hinsen [ 05/Feb/14 5:52 AM ]

This was handled long ago: https://github.com/clojure/algo.monads/commit/90909e30965bb59fccc8e527d31f8aaabc9d404b





Generated at Mon Dec 22 23:10:12 CST 2014 using JIRA 4.4#649-r158309.