Commit 6f665066 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby 👻

feat: Add rmap function.

parent 41f37f23
Pipeline #90475 passed with stages
in 1 minute and 10 seconds
......@@ -18,6 +18,7 @@ Hylang Truelisp
| cdr | Return rest of list | Function |
| append | Concat 2 list | Function |
| list? | True if arguement is an list | Function |
| rmap | Recursive impelmentation of map | Function |
| map-list | map l with function f | Function |
| reverse | Reverse list | Function |
| remove-last | Remove last element of list | Function |
......
......@@ -63,6 +63,14 @@
(setv f (λ [x y] (* x y)))
(test "(λ [x y] (* x y))" (= 8 (f 2 4)))
;;;
;;; Rmap.
;;;
(test "(rmap f [1 2 3 4])"
(= [2 3 4 5] (rmap (λ [x] (+ x 1)) [1 2 3 4])))
;;;
;;; Map-list.
;;;
......
......@@ -44,6 +44,10 @@
;;; List avanced functions.
;;;
(defn rmap [f l]
(if (empty? l) []
(cons (f (car! l)) (rmap f (cdr! l)))))
(defn map-list [f l]
(list (map f l)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment