Fork me on GitHub
#beginners
<
2018-04-25
>
deg15:04:10

I'm looking for a way to do something almost like partition-by. I have a very long string, and a long vector of {:start start1 :end end1} denoting substrings in the string. The vector is already sorted by position, and the substrings are guaranteed not to overlap. I need to collect a sequence of all these substrings, and another sequence of the intervening substrings. (That is, (f "0123456789" [{:start 0 :end 2} {:start 5 :end 8}]) ==> {:in ["01" "567"] :out ["" "234" "89"]}). The string is long enough that I may need to care about efficiency.

dpsutton15:04:43

(map (fn [{:keys [start end]}] (subs big-string start end)) positions) ?

dpsutton15:04:33

and build a function that builds the complements of the position specifiers

dpsutton16:04:00

or reduce over the big string taking up to the next indicator. just mash all of the start finishes into a list and reduce over those markers.

deg16:04:21

@dpsutton Thanks. Guess I'll try that and see if it is fast enough. I was afraid that the repeated subs over the entire big string would be quadratically painful. But, I should probably avoid premature optimization for now.

dpsutton16:04:08

painful is a measurement

dpsutton16:04:52

and if it is, just traverse once with the reduction, taking up to the next marker and alternating which collection it goes into

noisesmith16:04:24

reduce tracking both the collection of substrings and the last end index is likely the best mix of simple / performant. subs is cheap, much cheaper than treating the string as a seq

rnagpal18:04:29

I have a cljc file in lein project and I have cljc test for it in the test folder Now I want to include cljc test in both clj and cljs test runners and see the results of the tests to include and run cljc test in clj test runner, I have to compile it and :aot :all doesn’t seem to work in the test folder

rnagpal18:04:47

How do I compile the cljc file in test folder ?

Alex Miller (Clojure team)18:04:46

usually you don’t need to aot test files, but perhaps you have a gen-class or something that does require it. I’m not sure how to cause that to happen but #leiningen would perhaps be the best place to ask