Last active
April 25, 2024 15:55
-
-
Save PEZ/9e936a6097fdb1fd7a8418a22e3e1170 to your computer and use it in GitHub Desktop.
Duplicate a Sequence – Rich 4Clojure Problem 32 – See: https://github.com/PEZ/rich4clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns rich4clojure.easy.problem-032 | |
(:require [hyperfiddle.rcf :refer [tests]])) | |
;; = Duplicate a Sequence = | |
;; By 4Clojure user: dbyrne | |
;; Difficulty: Easy | |
;; Tags: [seqs] | |
;; | |
;; Write a function which duplicates each element of a | |
;; sequence. | |
(def __ :tests-will-fail) | |
(comment | |
) | |
(tests | |
(__ [1 2 3]) := '(1 1 2 2 3 3) | |
(__ [:a :a :b :b]) := '(:a :a :a :a :b :b :b :b) | |
(__ [[1 2] [3 4]]) := '([1 2] [1 2] [3 4] [3 4]) | |
(__ [[1 2] [3 4]]) := '([1 2] [1 2] [3 4] [3 4])) | |
;; To participate, fork: | |
;; https://github.com/PEZ/rich4clojure | |
;; Post your solution below, please! |
amiskov
commented
Aug 28, 2021
•
(def __ (fn [l] (->> l (map (fn [x] [x x])) (apply concat))))
(defn dup
[[frst & rst]]
(when frst
(lazy-seq (cons frst (cons frst (dup rst))))))
(def __ dup)
(def __ #(interleave % %))
(def __ (fn [cols] (mapcat #(list % %) cols)))
(def __ (fn [c] (mapcat (fn [a] [a a]) c)))
Really loving mapcat today
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment