I have a function that is defined like this:
(defn delete-rule [rules rule]
(om/transact! rules
(fn [rules] (into [] (remove #(= rule %) rules)))))
What is the purpose of into here?
Wouldn't that produce exactly the same result as the one on the above:
(defn delete-rule [rules rule]
(om/transact! rules
(fn [rules] (remove #(= rule %) rules))))
From the documentation for remove:
Returns a lazy sequence of the items in coll for which (pred item) returns false. pred must be free of side-effects. Returns a transducer when no collection is provided.
From the documentation for into:
Returns a new coll consisting of to-coll with all of the items of from-coll conjoined. A transducer may be supplied.
So the difference is, the delete-rule version with into returns a non-lazy vector, whereas the version without into returns a lazy sequence.
The particulars with your function is that om doesn't support lists (or lazy sequences) as cursors, only maps and vectors, that's why the output of remove must be converted to vector.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With