diff --git a/otus-18/src/otus_18/homework/core.clj b/otus-18/src/otus_18/homework/core.clj new file mode 100644 index 0000000..516e1eb --- /dev/null +++ b/otus-18/src/otus_18/homework/core.clj @@ -0,0 +1,77 @@ +(ns otus-18.homework.core + (:require [clojure.core.async :as a :refer [> (:names pokemon-type) + (filter (fn [type-name] (= lang (-> type-name :language :name)))) + (first) + :name)) + +(defn process-type [url lang] + (extract-type-name (r/fetch-type url) lang)) + +(defn process-pokemon [pokemon lang] + (let [pokemon-name (extract-pokemon-name pokemon) + type-urls (extract-pokemon-types-url pokemon) + types (map #(process-type % lang) type-urls)] + (println types) + {:name pokemon-name + :types types})) + + +(defn get-pokemons [limit lang] + (let [pokemons (take limit pokemons-seq)] + (map #(process-pokemon % lang) pokemons))) + +(comment + (take 10 types) + (get-pokemons 4 "en") + (take 2 pokemons-seq) + ) + + +;;; async solution + +(defn process-pokemon-async [pokemon lang] + (let [pokemon-name (extract-pokemon-name pokemon) + type-urls (extract-pokemon-types-url pokemon) + type-channels (mapv #(go (process-type % lang)) type-urls) + types-chan (a/into [] (a/merge type-channels))] + (go + (let [types (> (:names pokemon-type) - (filter (fn [type-name] (= lang (-> type-name :language :name)))) - (first) - :name)) +(ns otus-18.homework.pokemons + (:require [clojure.core.async :as a :refer [