I wanted to express "if this function is there, call it, else nil"
(some-> maybe-fn ())
but for some reason -> doesn't like it:
user=> (macroexpand '(-> maybe-fn ()))
(nil maybe-fn)ah it's because of first and rest of the form
(some-> maybe-fn (apply []))??
sure, there's ways to work around it
I feel like it wouldn't have occurred to me that (some-> maybe-fn ()) would work ... but now you mention it, it's interesting that it doesn't š
my workaround for this is to (let [f (or the-function identity)] ,,,) around the threading.
(defn run-plan-parallell
([plan processes] (run-plan-parallell plan processes {}))
([plan processes {:keys [limit]}]
(let [limiter (if limit
(partial take limit)
identity)]
(->> plan
plan->nses
shuffle
limiter
(bucketize processes)
(mapv #(future (test-namespaces-in-new-process (set %))))
(mapv deref)
(reduce merge)))))
I don't like the extra let too much, so maybe others have a better solution.Yeah I ended up with when-let
some-> is so close to optional chaining like foo?.bar?.baz?.()
I wonder if itās possible to change the implementation to allow:
(some-> foo (.-bar) (.baz))doesn't that already work?
for all but the last part to make baz?.() work
yes it does:
cljs.user=> (some-> #js {:bar #js {:baz (fn [] (prn :dude))}} (.-bar) (.baz))
dude:
oh the last part ok
yeah then -> needs to change
which I'm all for
but it's probably not going to happen
hereās a safe-> macro that works: https://gist.github.com/shaunlebron/0950a2a2e65beec6c121dff3de6309f1
Does anyone know why assoc works for vectors but dissoc doesn't? I would expect either both to work or neither
Something else that comes to mind is that dissoc is the inverse of assoc. But that only holds true for maps and sets. I don't think all cases of assoc followed by dissoc on a vector brings you back to the original vector value.
I think this is what was tripping me up
because it cannot not have the key. notice assoc on vectors fails outside of the length of it.
settings=> (assoc [] 0 :hi)
[:hi]
settings=> (assoc [] 4 :hi)
Execution error (IndexOutOfBoundsException) at metabase.analytics.settings/eval294488 (REPL:20).
null
settings=> (assoc [] 1 :hi)
Execution error (IndexOutOfBoundsException) at metabase.analytics.settings/eval294490 (REPL:21).
nullsettings=> (assoc [:not-empty] 1 :hi)
[:not-empty :hi]but you cannot have a vector [:first :second <literally no value here> :fourth] . Thereās no way for a sequential structure to not have a third item
Couldn't it have natural number keys to dissoc? I'm not sure I follow
if you removed the first item from this vector, what would you expect the resulting structure to be? [0 1 2] ?
I would expect (dissoc [0 1 2] 1) to return [0 2]
wouldnāt that still have an item at index 1 though?
You're saying because of the underlying data structure?
> clojure.core/dissoc > ([map] [map key] [map key & ks]) > dissoc[iate]. Returns a new map of the same (hashed/sorted) type, > that does not contain a mapping for key(s). the docstring says wonāt have that key any longer. but your return value does have a value
settings=> (get [0 2] 1)
2how can you remove the key 1 , or the notion of āthe second itemā in a vector ?
oh I see what you're saying š¤¦š»āāļø
yeah. itās possible it could āpopā off the end but it doesnāt do that. the same way you can assoc a new element at the end, or replace in the āinteriorā of the vector