Fork me on GitHub
#beginners
<
2019-03-05
>
sogaiu02:03:21

@clardata6249 have been going through it recently with a friend who is learning and it still feels quite relevant

sogaiu03:03:05

happy reading :)

Vishal Gautam04:03:16

Hello I am trying to integrate reagent snippets using klipse in an reagent application. But I am having an issue. I get this error when I try to load Reagent. `Execution error. ERROR: Error: No protocol method ISwap.-swap! defined for type cljs.core/Atom: [object Object]`. Help anyone? Here is what html file looks like

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">


    <link href="/css/styles.css" rel="stylesheet" type="text/css">
    <link rel="icon" href="/img/favicon.ico">

    <title>Klipse Reagent Demo</title>

    <link rel="stylesheet" type="text/css" href="">

    <script>
      window.klipse_settings = {
        selector: '.language-klipse',
        selector_reagent: '.language-reagent',
      }
    </script>

  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="app"></div>
    <script src="/js/main.js" type="text/javascript"></script>


    <script src=""></script>
  </body>
</html>

Vishal Gautam04:03:47

reagent entry file

(ns app.core
  (:require [reagent.core :as r]
            [re-frame.core :as rf]
            [app.db]
            [app.views :refer [app]]
            [app.services]))

(defn ^:dev/after-load start
  []
  (rf/dispatch-sync [:initialize-db])
  (r/render [app]
    (.getElementById js/document "app")))

(defn ^:export init
  []
  (start))

Vishal Gautam04:03:18

views

(ns app.views
  (:require [re-frame.core :as rf]))

(defn cljs-code [code]
  [:pre
   [:code {:class "language-klipse"} code]])
;
(defn reagent-code [code]
  [:pre
   [:code {:class "language-reagent"} code]])

(defn app
  []
  [:div
   [cljs-code "(require '[reagent.core :as r])"]
   [reagent-code "(defn app [] [:div 'hello world'])"]
   [:h1 "Re-frame application"]
   [:button {:on-click #(rf/dispatch [:add-product-to-freezer {:name :vanilla
                                                               :amount 20}])}
    "Add"]])

foamdino07:03:18

can anyone help with some performance tuning?

foamdino07:03:07

using criterium I've narrowed down my issue to calling (apply merge data) where data is a sequence of maps

foamdino07:03:53

when I benchmark this however criterium gives me 'ok' results

foamdino07:03:05

Execution time mean : 46.888422 ms

foamdino07:03:19

however the wall clock time for this is measured in minutes

foamdino07:03:34

^ like 10-15 minutes

foamdino07:03:27

the amount of data is large

dpsutton07:03:56

Try (into {} merge data)?

foamdino07:03:56

I tried that - still takes stupid amounts of time

foamdino07:03:00

I think the issue is that the data collection is lazy and apply is realizing it

foamdino07:03:55

and this process is consuming all the time, before the actual merge step happens

foamdino07:03:20

so (take 10 data) is quick

foamdino07:03:31

but (count data) is slow

foamdino07:03:17

which is another hint

foamdino08:03:51

so I have data in this format: ({11266661 {:shipment-dispatch 0, :stock-adjustment 0, :receipt 0}} {11185294 {:shipment-dispatch 0, :stock-adjustment 0, :receipt 0}} {11664105 {:shipment-dispatch 0, :stock-adjustment 0, :receipt 0}}... <- lazy sequence

foamdino08:03:25

and I need it in this format: {11266661 {:shipment-dispatch 0, :stock-adjustment 0, :receipt 0}, 11185294 {:shipment-dispatch 0, :stock-adjustment 0, :receipt 0}, 11664105 {:shipment-dispatch 0, :stock-adjustment 0, :receipt 0}} <- realized map

foamdino08:03:12

is there a way to achieve this using (loop) or some other less functional means as it seems that this is where performance is crippling me

foamdino08:03:55

(apply merge data) is too slow for the data size as is (apply into {} data)

foamdino08:03:09

and I need to retain the semantics of the merge

Twice10:03:07

@foamdino have you considered using Reducers? kinda looks like it's appropriate situation for them

foamdino10:03:46

@alisher.atantayev is there a standard idiom for converting from (apply merge ...) to a reducer?

borkdude10:03:05

@foamdino have you tried a transient variation of merge?

Twice10:03:06

@foamdino I've just tried a version with reducers - it's actually slower than just (apply merge data)

Twice10:03:37

what kind of data size are we talking about here?

foamdino10:03:40

very large 🙂

Twice10:03:15

like what? billions?

borkdude10:03:34

FWIW we have parts in our code where we drop back to mutable Java HashMaps for performance reasons when dealing with “very large” data

Twice10:03:28

Btw, speaking of large data - has anyone used cheshire to lazy load json content in a particular nested node? For example, I have json like {"package": "354", "misc-info": {..}, "entries": [{...lots of data...}]} and I need to lazy-parse precisely the "entries" part of json file. I'm not sure cheshire's parsed-seq is suitable here. Is there a way to achieve that?

borkdude10:03:52

@alisher.atantayev Interesting. I’ve mentioned this case once in the #ring-swagger channel where I asked if maybe jsonista could support this (cc @ikitommi). I haven’t tried this myself yet.

borkdude10:03:19

It should be possible using the lower level Java API

Twice10:03:19

should I ask it on clojure channel, may be someone encountered this before?

foamdino10:03:19

I'm taking a look at transients - never seen these before, may be helpful

Audrius15:03:20

how to map a vector of keywords to add a string to them? [ :a :b :c] => [::ns/a ::ns/b ::ns/c]

flefik15:03:58

i think you want to use keyword

flefik15:03:03

(map #(keyword ":ns" (name %)) [:a :b :c])

đź‘Ť 5
Mario C.15:03:34

(map #(keyword (str ":ns/" (name %))) [:a :b :c]) something like this?

yuhan15:03:20

I don't think either of the above actually get expanded to namespaced symbols (which is what I assume is wanted here)

flefik15:03:23

use symbol?

yuhan15:03:59

*namespaced keywords, sorry

yuhan15:03:26

(require '[clojure.string :as string])

(keyword ":string" "foo") ;; => ::string/foo

(= ::string/foo (keyword ":string" "foo")) ;; => false

flefik15:03:31

oh you are right, the docs even say so

yuhan15:03:34

because ::string/foo gets expanded out at compile time to :clojure.string/foo

flefik15:03:33

you want to define these as namespaced symbols?

yuhan15:03:19

perhaps best to use the full ns name instead of the alias?

yuhan15:03:11

otherwise it's also possible to retrieve the full namespace

yuhan15:03:18

#(keyword (namespace ::string/-) (name %))

Mario C.15:03:49

Interesting, didn't know that

willahhh19:03:44

Hello, is there a native function to get values of a large lazy seq between a start and end param ? Something like (nth-range 1 2 [“a”, “b” “c”])

dpsutton19:03:20

you should be able to use drop and take to achieve that

Kaden Taylor19:03:42

Hey guys, is there still a cursive channel? Got a (probably silly) formatting question.

dpsutton19:03:56

of course! good luck