fix: keyword/set/map as IFn in higher-order fns; nil-seq; take-nth/interpose/sort-by/min-key arities
Biggest fix: jolt keywords are Janet keywords and maps are Janet structs/phm, but (:a struct) at the Janet level returns nil (not a Clojure accessor) and errors on a phm — so core-map/filter/sort-by/group-by/etc. calling (f x) directly broke the ubiquitous keyword/set/map-as-function idioms ((map :a coll), (sort-by :k coll), (filter a-set coll), (group-by :type coll)). Added as-fn coercion (keyword/symbol -> key lookup, map -> key lookup, set -> membership) applied at the entry of map/filter/remove/keep/mapv/filterv/sort-by/group-by/partition-by/some/ not-any?/not-every?/take-while/drop-while/min-key/max-key. Also: - realize-for-iteration treats nil as an empty seq (Clojure semantics), fixing nth/nthrest/nthnext/take-last/reduce/doseq over nil. - take-nth and interpose gained their 1-arg transducer arities. - sort-by gained the 3-arg (keyfn comparator coll) form. - min-key/max-key: single item returns it without calling f; ties keep the last. - underive gained the 2-arg global-hierarchy form. clojure-test-suite pass 3535->3649, errors 177->122, clean files 39->44. spec: seq/IFn-values-as-functions (11). jpm test green.
This commit is contained in:
parent
acfcf2f94b
commit
2ccfa675f7
3 changed files with 99 additions and 24 deletions
|
|
@ -103,3 +103,18 @@
|
|||
["take cycle" "[1 2 1 2 1]" "(take 5 (cycle [1 2]))"]
|
||||
["take repeatedly" "3" "(count (take 3 (repeatedly (fn [] 1))))"]
|
||||
["take-last of range" "[8 9]" "(take-last 2 (range 10))"])
|
||||
|
||||
# Clojure IFn values used as the function arg to higher-order fns: a keyword or
|
||||
# symbol looks up a key, a set tests membership, a map looks up a key.
|
||||
(defspec "seq / IFn values as functions"
|
||||
["map keyword" "[1 2 3]" "(map :a [{:a 1} {:a 2} {:a 3}])"]
|
||||
["filter keyword" "[{:ok true}]" "(filter :ok [{:ok true} {:ok false}])"]
|
||||
["remove keyword" "[{:ok false}]" "(remove :ok [{:ok true} {:ok false}])"]
|
||||
["sort-by keyword" "[{:a 1} {:a 2} {:a 3}]" "(sort-by :a [{:a 3} {:a 1} {:a 2}])"]
|
||||
["sort-by key + cmp" "[{:a 3} {:a 2} {:a 1}]" "(sort-by :a > [{:a 3} {:a 1} {:a 2}])"]
|
||||
["filter set" "[2 4]" "(filter #{2 4} [1 2 3 4 5])"]
|
||||
["remove set" "[1 3 5]" "(remove #{2 4} [1 2 3 4 5])"]
|
||||
["group-by keyword" "{1 [{:n 1}], 2 [{:n 2}]}" "(group-by :n [{:n 1} {:n 2}])"]
|
||||
["map a map" "[1 nil 2]" "(map {:a 1 :b 2} [:a :z :b])"]
|
||||
["take-nth transducer" "[0 2 4 6 8]" "(into [] (take-nth 2) (range 10))"]
|
||||
["interpose transducer" "[1 :x 2]" "(into [] (interpose :x) [1 2])"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue