Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active April 25, 2024 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PEZ/9e936a6097fdb1fd7a8418a22e3e1170 to your computer and use it in GitHub Desktop.
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
(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
Copy link

amiskov commented Aug 28, 2021

(def __ #(interleave % %))

@szalai1
Copy link

szalai1 commented Sep 22, 2021

(def __ (fn [l] (->> l (map (fn [x] [x x])) (apply concat))))

@status203
Copy link

(defn dup
  [[frst & rst]]
  (when frst
    (lazy-seq (cons frst (cons frst (dup rst))))))

(def __ dup)

@StanTheBear
Copy link

(def __ #(interleave % %))

@simonl91
Copy link

(def __ (fn [cols] (mapcat #(list % %) cols)))

@natef-GuruTech
Copy link

(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