替代clojure中的可变数据结构

时间:2015-08-25 16:34:59

标签: clojure apache-spark flambo

我在clojure中开发了一个函数来填充最后一个非空值的空列,我使用flambo这是一个apache-spark包装器,使用clojure来实现它的一些功能

(:require [flambo.api :as f])

(defn replicate-val
  [rdd input ]
  (let [{:keys [ col ]} input
    prev-col-val (atom [])
    result (f/map rdd (f/fn [ row ]
                                (if-not (s/blank? (get row col))
                                  (do
                                    (swap! prev-col-val assoc 0 (get row col))
                                    row)
                                  (assoc row col (get @prev-col-val 0)))))]
result))

我不喜欢改变prev-col-val来跟踪状态的想法, 关于如何重构上述内容以保留clojure的不可变数据结构的任何想法?

输入格式为:

[["04" "2" "3"] ["04" "" "5"] ["5" "16" ""] ["07" "" "36"] ["07" "" "34"] ["07" "25" "34"]]

并且所需的输出是:

[["04" "2" "3"] ["04" "2" "5"] ["5" "16" ""] ["07" "16" "36"] ["07" "16" "34"] ["07" "25" "34"]]

由于

0 个答案:

没有答案