-
-
Save Slackwise/c8f2af25bcc2598096e4 to your computer and use it in GitHub Desktop.
Implementing the comp function, as an exercise recommended from http://www.braveclojure.com/functional-programming/
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 foo | |
(:require [clojure.string :as s])) | |
(defn my-comp | |
[& funcs] | |
(fn [& args] | |
(loop [fs (reverse funcs), results args] | |
(if (empty? fs) | |
(first results) | |
(recur (rest fs) (conj [] (apply (first fs) results))))))) | |
(defn trim-then-caps | |
[string] | |
((my-comp s/trim s/upper-case) string)) | |
(println (str "{" (trim-then-caps " a lowercase string of sadness ") "}")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment