Как понять, что вот проект А пишется на Java, а вот проект B ужеее неее, на Scala или Groovy лучше будет.
Тогда если он такой крутой, почему я за 6 лет в айти(не коммерческого, но всетаки был рядом) не слышал почти про него
И где тогда куча вакансий на него?
Так с чего начать: Scala или Erlang(Elixir?)?
Что перспективнее у нас/за рубежом?
И можно их учить без знания Java?
In general, the semantics of the Scala Native language are the same as Scala on the JVM. However, a few differences exist, which we mention here.
(ns su.gornostaev.rstatfr2csv
(:use [clojure.xml :only (parse)])
(:use [clojure.string :only [index-of join split]])
(:use [clojure.java.io])
(:import java.io.File))
(defn parse-cmd
[args]
(when-let [file-name (first args)]
file-name))
(defn parse-file
[file-name]
(if (nil? file-name) nil (parse (File. file-name))))
(defn format-datetime
[dt]
(let [[date time] (split dt #"\s")]
(str (join "." (reverse (split date #"\."))) " " (subs time 0 (index-of time \:)) ":00")))
(defn merge-counters
[counters]
(map
(fn [item]
(let [[k & v] item]
(assoc (reduce (fn [acc val] (merge-with + acc val)) (first v)) :dt k)))
(reduce
(fn [acc val]
(let [{:keys [dt in out]} val]
(update-in acc [dt] (fnil #(conj % {:in in :out out}) []))))
{} counters)))
(defn parse-counters
[sensor]
(map
(fn [counter]
{:dt (format-datetime (:datetime (:attrs counter)))
:in (read-string (:realin (:attrs counter)))
:out (read-string (:realout (:attrs counter)))})
sensor))
(defn parse-sensors
[shop]
(map
(fn [sensor]
{:name (:name (:attrs sensor)) :counters (merge-counters (parse-counters (:content sensor)))})
shop))
(defn parse-shops
[dom]
(map
(fn [shop]
{:name (:name (:attrs shop)) :sensors (seq (parse-sensors (:content shop)))})
dom))
(defn parse-doc
[doc]
(parse-shops
(->>
doc
:content
first
:content)))
(defn save-csv
[data]
(with-open [w (writer (file "output.csv"))]
(doseq [shop data]
(doseq [sensor (:sensors shop)]
(doseq [counter (:counters sensor)]
(.write w (str (join "\t" (concat [(:name shop) (:name sensor)] (vals (into (sorted-map) counter)))) "\n")))))))
(save-csv (parse-doc (parse-file (parse-cmd *command-line-args*))))
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0) + "ns")
result
}
// Now wrap your method calls, for example change this...
val result = 1 to 1000 sum
// ... into this
val result = time { 1 to 1000 sum }