Implement ALL for strings (#333)

This commit is contained in:
tommy 2024-09-16 11:10:52 -04:00 committed by GitHub
parent 67e8680602
commit 9a615ff22c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -95,6 +95,13 @@
(comp (map next-fn)
(filter not-NONE?))
structure))
#?(:clj String :cljs string)
(all-transform [structure next-fn]
(apply str (into []
(comp (map next-fn)
(filter not-NONE?))
structure)))
#?(:clj clojure.lang.PersistentHashSet :cljs cljs.core/PersistentHashSet)
(all-transform [structure next-fn]

View file

@ -1440,6 +1440,15 @@
(is (= "abq" (setval s/LAST "q" "abc")))
)
(defn whitespace? [char]
(re-matches #"\s" (str char)))
(deftest string-transform-test
(is (= "123" (transform s/ALL identity "123")))
(is (= "123" (transform [s/ALL whitespace?] s/NONE "1 2 3")))
#?(:clj (is (= "123" (setval [s/ALL #(Character/isWhitespace %)] s/NONE "1 2 3"))))
#?(:clj (is (= "123" (transform [(s/filterer #(Character/isWhitespace %))] s/NONE "1 2 3")))))
(deftest regex-navigation-test
;; also test regexes as implicit navs
(is (= (select #"t" "test") ["t" "t"]))