Fork me on GitHub
#clojurescript
<
2020-04-01
>
roninhacker00:04:44

Had to share this: building an index of words as a series of nested maps (if you've ever written a hangman solver you've done this), and I have three components I want to concat into a vector of letters: • a vector of letters • a letter • a string I want to do it in order, so the end result is [\e \a \c \h \l \e \t \t \e \r \a \n \e \n \t \r \y] How to do this? Obv. this isn't a hard algorithmic problem, but how to do it cleanly? I mess around with big transformations (apply vector) and (apply str) everywhere), hate it, and come up with: (into (conj vector-of-letters letter) string) This is a lot better than the earlier mutant that used type conversions and apply everywhere, but still.... Knowing that strings are technically collections, I wonder if I can cut a fn call by doing something like: (reduce conj vector-of-letters letter string), but this throws an error because reduce only takes three args---f, initial-value, and a collection (I was trying to reduce over "letter + string" in my head) But then I remember that into is basically (reduce conj), and, the clever part: clojurescript doesn't have chars, just one-letter strings, so letter is not a char, but a string---or, in other words, a collection. Behold! (reduce into vector-of-letters '(letter string)) if you try this: (reduce into ["a" "b" "c"] '("d" "efg")) => returns ["a" "b" "c" "d" "e" "f" "g"] (pitfall is this only works in cljs; (reduce into ["a" "b" "c"] '(\d "efg")) will work in cljs as \d evaluates as \`"d"`, but will throw an error in clojure-land where there is a dedicated char type) Still a muted "Eureka" was heard.

🍪 4
4
lilactown02:04:35

quite clever 🙂

OrdoFlammae23:04:56

What are the differences between Figwheel, Figwheel Main, and Shadow?

OrdoFlammae23:04:26

From what I understand, Figwheel Main is supposed to be an updated version of Figwheel, but people still use the old version.

dnolen23:04:29

Figwheel Main is modeled after cljs.main - so it's designed to be deps (as in deps.edn) friendly

dnolen23:04:50

the original figwheel was more oriented around lein (which a lot of people still use)

dnolen23:04:37

shadow is really a complete build tool that covers a pretty large variety of use cases

OrdoFlammae23:04:45

Is there an analogous framework for Boot?

dnolen23:04:06

hrm I don't know I don't follow boot that closely

dnolen23:04:11

but that really shouldn't be necessary

dnolen23:04:26

deps.edn stuff are not plugins - they're mostly reusable with any tool

OrdoFlammae23:04:42

So is Shadow more of in the class of lein or boot, but for cljs?

dnolen23:04:40

no - I just mean it covers a lot of use cases under one tool - web, node, react-native, provide own repl / hotloader