Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Last active January 3, 2016 06:09
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 Slackwise/c8f2af25bcc2598096e4 to your computer and use it in GitHub Desktop.
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/
(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