code-reviews

2020-10-30T03:59:27.048300Z

(defn ->char-strings [str]
  (let [iter (doto (BreakIterator/getCharacterInstance)
               (.setText str))]
    (loop [start (.first iter)
           res []]
      (let [end (.next iter)]
        (if (= end BreakIterator/DONE)
          res
          (recur
            end
            (conj res (subs str start end))))))))
Wrote a quick function that “splits” up complex unicode with Java’s ICU4J Not sure if above is the most clojury soln. If you have better ideas lmk!

Ben Sless 2020-10-30T13:05:49.048700Z

Some really minor stuff, like see if you can use identical? instead of = in (= end BreakIterator/DONE) , or make res transient inside the loop, but these are all optimizations

❤️ 1
2020-10-30T15:46:41.049Z

Thanks Ben. Noob q: what do you mean by make res transient inside the loop?

Ben Sless 2020-10-30T15:47:31.049200Z

like so:

(defn ->char-strings [str]
  (let [iter (doto (BreakIterator/getCharacterInstance)
               (.setText str))]
    (loop [start (.first iter)
           res (transient [])]
      (let [end (.next iter)]
        (if (= end BreakIterator/DONE)
          (persistent! res)
          (recur
           end
           (conj! res (subs str start end))))))))

2020-10-30T15:53:24.049400Z

aah! I didn’t know about this fn! Thanks Ben

👍 1
seancorfield 2020-10-30T04:12:25.048500Z

Looks reasonable to me.

❤️ 1