Skip to content

Commit

Permalink
Fix list-ops test
Browse files Browse the repository at this point in the history
  • Loading branch information
kahgoh committed Sep 22, 2024
1 parent 9930f51 commit 8ca6bc0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions exercises/practice/list-ops/.meta/src/example.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
(ns list-ops)

(defn foldl [f list init]
(loop [acc init l list]
(cond
(empty? l) acc
:else (recur (f acc (first l)) (rest l)))))

(defn append [list1 list2]
(list-ops/foldl (fn [acc elem] (conj acc elem)) list2 list1))

Expand All @@ -20,14 +26,9 @@

(defn map [f list]
(list-ops/foldl (fn [acc elem] (conj acc (f elem))) list []))
(defn foldl [f list init]
(loop [acc init l list]
(cond
(empty? l) acc
:else (recur (f acc (first l)) (rest l)))))

(defn reverse [list]
(list-ops/foldl (fn [acc elem] (cons elem acc)) list []))

(defn foldr [f list init]
(list-ops/foldl f (list-ops/reverse list) init))

(defn reverse [list]
(list-ops/foldl (fn [acc elem] (cons elem acc)) list []))

0 comments on commit 8ca6bc0

Please sign in to comment.