Fork me on GitHub
#clojurescript
<
2020-09-06
>
drewverlee03:09:08

Err. @misha ((frequencies "\n\n") "\n") => 2 But I didn't expect the behavior of split lines. I would have expected a blank string for each new line

misha09:09:05

yeah, frequencies seems to be 10x faster than count re-seq, but regex is actually #"\n\r|\r\n|\n|\r" or something like this.

misha09:09:03

all those shenanigans are exactly because empty strings are omitted from "default" tools you'd reach for :(

misha10:09:36

* 10x faster on that little useless string that is. on an actual text (any source code file) - it is ∞ slower (imagine frequencies clojure.core.clj just to count lines :))

drewverlee12:09:31

If the source is big enough use the reducer library/ns.

drewverlee12:09:59

If it's bigger then that then you use onyx

drewverlee12:09:52

On the backend/clojure of course.

misha12:09:58

~20k lines, worst case scenario – need to run it within 16msec to maintain 60fps opieop on client, hence writing in #clojurescript channel

misha12:09:41

(ofc. for such use case, there will be more involved datastructures and supporting state, so lines count will be custom fn, etc. the point of the PSA - str/split-lines ignores empty lines.)