meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
ingesol 2019-12-09T09:01:14.437800Z

Hi! I’m suspecting there is some more declarative way of doing this than the stateful fn I made so far?

(let [next-avatar (let [i      (atom -1)
                        avatars (cycle [:avatar1 :avatar2 :avatar3 :avatar4])]
                    #(nth avatars (swap! i inc))) ]
  (m/search src-list
            (m/scan {:first-name ?first-name
                     :last-name  ?last-name})
            {:full-name (str ?first-name " " ?last-name)
             :avatar    (next-avatar)}))

noprompt 2019-12-09T17:59:12.442200Z

@ingesol Hmm… I don’t have a much better answer here as far as patterns go. I’m assuming this is a small example but I’d probably push the map construction a bit further out.

(let [full-names (m/search src-list
                   (m/scan {:first-name ?first-name
                            :last-name  ?last-name})
                   (str ?first-name " " ?last-name))
      avatars (cycle [:avatar1 :avatar2 :avatar3 :avatar4])]
  (map (fn [full-name avatar]
         {:full-name full-name
          :avatar avatar})
       full-names
       avatars))

ingesol 2019-12-09T18:49:29.443500Z

@noprompt Right, makes sense. Given that I’m new to meander, I was just wondering if there was a natural way to express this. Thanks!

noprompt 2019-12-09T18:51:48.443800Z

No problem!