You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assoc and assoc-in are analogous to put and put-in without the side effects.
There is first which is sometimes more convenient than (map (fn [x] (x 0)) xs). However, there isn't a second so we have (map first xs) and (map (fn [x] (x 1)) xs)`.
There may be more of them that could be useful for FP that I haven't thought of ATM.
Would it be a good idea to add them as part of spork?
The text was updated successfully, but these errors were encountered:
Inc0n
changed the title
conj? assoc? Adding a few more functional operators
assoc? Adding a few more functional operators
Apr 6, 2023
Hello, rn I'm indeed playing with that idea, I don't know if its the best way to do it, but by design it is not going to be performant anyway :V
(defnassoc [dskv&ekvs]
(cond
(struct?ds) (struct ;(kvsds) kv ;ekvs)
(and (tuple?ds) (empty?ekvs) (number?k))
(if (=k (lengthds))
(tuple ;dsv)
(tuple ;(sliceds0k) v ;(sliceds (inck) (lengthds))))
(error"ds must be a struct or a tuple and tuples' keys must be numbers, also tuples do'nt accept extra kv's")))
(defnassoc-in [ds [k&ks] v]
(if (empty?ks)
(assocdskv)
(assocdsk (assoc-in (getdsk {}) ksv))))
AFIK it works as in clojure, it is something trivial enough so people can add it to their projects by themselves, but I think it would be nice to have it at hand with spork
Assoc
andassoc-in
are analogous toput
andput-in
without the side effects.There is
first
which is sometimes more convenient than(map (fn [x] (x 0)) xs)
. However, there isn't asecond
so we have(map first xs) and
(map (fn [x] (x 1)) xs)`.There may be more of them that could be useful for FP that I haven't thought of ATM.
Would it be a good idea to add them as part of spork?
The text was updated successfully, but these errors were encountered: