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 7763463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:39:56+00:00 2026-06-01T14:39:56+00:00

In answering a question about a function that maps over multiple functions with the

  • 0

In answering a question about a function that maps over multiple functions with the same arguments (A: juxt), I came up with a function that basically took the same form as juxt, but used map:

(defn could-be-lazy-juxt
  [& funs]
  (fn [& args]
    (map apply funs (repeat args))))

=> ((juxt inc dec str) 1)
[2 0 "1"]
=> ((could-be-lazy-juxt inc dec str) 1)
(2 0 "1")

=> ((juxt * / -) 6 2)
[12 3 4]
=> ((could-be-lazy-juxt * / -) 6 2)
(12 3 4)

I have little clue about the laziness or performance of it, but timing in the REPL does suggest something lazy-ish is going on.

=> (time (apply (juxt + -) (range 1 100)))
"Elapsed time: 0.097198 msecs"
[4950 -4948]
=> (time (apply (could-be-lazy-juxt + -) (range 1 100)))
"Elapsed time: 0.074558 msecs"
(4950 -4948)

=> (time (apply (juxt + -) (range 10000000)))
"Elapsed time: 1019.317913 msecs"
[49999995000000 -49999995000000]
=> (time (apply (could-be-lazy-juxt + -) (range 10000000)))
"Elapsed time: 0.070332 msecs"
(49999995000000 -49999995000000)

I’m sure this function is not really that quick (the print of the outcome ‘feels’ about as long in both). Doing a ‘take x’ on the function only limits the amount of functions evaluated, which probably is limited in it’s applicability, and limiting the other parameters by ‘take’ should be just as lazy in normal juxt.

Is this juxt really lazy ? Would a lazy juxt bring anything useful to the table, for instance as a compositing step between other lazy functions ? What are the performance (mem / cpu / object count / compilation) implications ?
Why is the Clojure juxt implemented with a reduce and returns a vector, which breaks laziness ?

  • 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-01T14:39:58+00:00Added an answer on June 1, 2026 at 2:39 pm

    Yes your implementation of juxt is lazy by virtue of only calling map which is lazy.

    it’s hard to call it in it’s present form with out realizing the arguments in the caller (by using apply. so I changed it a bit to take a sequence of functions:

    user> (defn could-be-lazy-juxt
      [funs]
      (fn [& args]
        (map #(apply %1 %2) funs (repeat args))))
    #'user/could-be-lazy-juxt
    

    then define a lazy sequence of functions that make a lot of output when it’s realized

    user> (defn loud-seq [len] (take len (map #(do (println "produced a function") %) (cycle [inc dec]))))
    #'user/loud-seq
    

    then use juxt to make a function out of this lazy sequence of functions

    user> (def f (could-be-lazy-juxt (loud-seq 50)))
    #'user/f
    

    as you can see the list is still lazy, it realizes it’s list of functions when it’s resulting function is called.

    so lets call it:

    user> (f 1)
    (produced a function
    produced a function
    2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 produced a function
    produced a function
    0 2 0)
    user> 
    

    I leave the reasons for doing so up to you 😉

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

Sidebar

Related Questions

While answering to a question about that here: https://stackoverflow.com/a/9872630/82609 I tried to do the
I came up with this after answering this question I had a simple function
thanks all of you for patiently answering my question About exec() function in PHP:
After answering a question about how to force-free objects in Java (the guy was
Before answering, it is not as easy question as you might have thought about
When answering another question, I realized that the following program does not quite do
This question arose when I was working on answering another question about best practices
I was answering a Question about how to show a directory structure on FTP
I know this is quite a vague question -- sorry about that. If I
Before answering this question, understand that I am not asking how to create my

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.