Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:43:12+00:00 2026-06-11T05:43:12+00:00

I have this nagging problem: Wrappers are functions that take a function, and returns

  • 0

I have this nagging problem:

Wrappers are functions that take a function, and returns another function that takes in a parameter, does something to the parameter and sticks it back into the function.

(defn wrapper [func]
  (fn [params]
    (func (do-something-to params))))

and what I’d like to do is to track parameter changes as it goes from wrapper to wrapper

for example, I can define two wrappers:

(defn wrap-inc [func]
  (comp func inc))

(defn wrap-double [func]
  (comp func #(* % 2)))

then,

(def h (-> #(* % 3)
       wrap-inc
       wrap-double))

is equivalent to:

(def h (fn [x] (* (inc (* 2 x)) 3)))
(h 1) => 9

Now, I would want to define dbg-> so that

(def h-dbg (dbg-> #(* % 3)
                  wrap-inc
                  wrap-double))

to still give me the same functional equivalent, but also keep track of old and new values:

(h-dbg 1) => 9

but will also display debug infomation in the console:

"wrap-double: (in: 1, out: 2)"
"wrap-inc: (in: 2, out 3)"

This sort of pattern will be extremely useful to debug ring wrappers like this to figure out what each one is doing, for example, this typical example:

(defn start []
  (jetty/run-jetty
   (-> #'routes-handler
       ;;(wrap-reload-modified ["clj-src"])
       (wrap-file "resources/public")
       wrap-file-info
       wrap-decamelcase-params
       wrap-keyword-params
       wrap-nested-params
       wrap-params
       wrap-ignore-trailing-slash) {:port 8890 :join? false}))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:43:13+00:00Added an answer on June 11, 2026 at 5:43 am

    I believe you’re looking for something called the writer monad.

    Here’s a nice explanation of the Writer monad and some examples of it in action (sorry, it’s in Haskell).

    Basically, this monad helps you compose functions that also return, in addition to their “normal” output, a logging value. For example, if you had functions with these types:

    f :: a -> (b, l)
    g :: b -> (c, l)
    

    you could use the writer monad to compose them to get a new function with type:

    h :: a -> (c, l)
    

    Warning: the Clojure macros -> and ->> can’t be used in the exact same way when composing monadic functions, since you need to use bind for composition.

    As an alternative solution, you could use a side-effecting wrapper:

    (defn wrapper
      [f]
      (fn [& params]
          (print params) ;; or some other logging operation
          (apply f params)))
    

    This works because the value of the last expression in the body of a function is its return value — previous expressions are evaluated and their results thrown away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I'm probably worrying about wrong optimization, but I have this nagging thought that it's
I've been pondering this today, and I have a nagging feeling that this is
I've written an entire app pretty successfully in Django but I have this nagging
I have this function // add history paths and save data function AddPath( strTag,
i have this youtube url http://www.youtube.com/watch?v=9N51Etoikfw&feature=youtube_gdata i need to remove the feature parameter and
This is an annoying problem I am having with Twisted.web. Basically, I have a
This problem has been bothering me for sometime now, I have not settled on
I have had a nagging feeling for some time that I may be ignoring
This is a question that's been nagging me for some time. I always thought

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.