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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:12:05+00:00 2026-05-25T10:12:05+00:00

I have an incoming lazy stream lines from a file I’m reading with tail-seq

  • 0

I have an incoming lazy stream lines from a file I’m reading with tail-seq (to contrib – now!) and I want to process those lines one after one with several “listener-functions” that takes action depending on re-seq-hits (or other things) in the lines.

I tried the following:

(defn info-listener [logstr]
  (if (re-seq #"INFO" logstr) (println "Got an INFO-statement")))

(defn debug-listener [logstr]
  (if (re-seq #"DEBUG" logstr) (println "Got a DEBUG-statement")))

(doseq [line (tail-seq "/var/log/any/java.log")] 
   (do (info-listener logstr)
       (debug-listener logstr)))

and it works as expected. However, there is a LOT of code-duplication and other sins in the code, and it’s boring to update the code.

One important step seems to be to apply many functions to one argument, ie

(listen-line line '(info-listener debug-listener))

and use that instead of the boring and error prone do-statement.

I’ve tried the following seemingly clever approach:

(defn listen-line [logstr listener-collection]
  (map #(% logstr) listener-collection))

but this only renders

(nil) (nil)

there is lazyiness or first class functions biting me for sure, but where do I put the apply?

I’m also open to a radically different approach to the problem, but this seems to be a quite sane way to start with. Macros/multi methods seems to be overkill/wrong for now.

  • 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-05-25T10:12:06+00:00Added an answer on May 25, 2026 at 10:12 am

    Making a single function out of a group of functions to be called with the same argument can be done with the core function juxt:

    =>(def juxted-fn (juxt identity str (partial / 100)))
    =>(juxted-fn 50)
    [50 "50" 2]
    

    Combining juxt with partial can be very useful:

    (defn listener [re message logstr] 
      (if (re-seq re logstr) (println message)))
    


    (def juxted-listener 
      (apply juxt (map (fn [[re message]] (partial listner re message)) 
         [[#"INFO","Got INFO"],
          [#"DEBUG", "Got DEBUG"]]))
    


    (doseq [logstr ["INFO statement", "OTHER statement", "DEBUG statement"]] 
      (juxted-listener logstr))
    

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

Sidebar

Related Questions

I have a incoming stream of bytes (unsigned char) from either a file or
I have an incoming stream of messages, and want a window that allows the
I have 1 process that receives incoming connection from port 1000 in 1 linux
I have pulled an incoming changes from a codeplex-based mercurial repository and have arrived
I have a process where an incoming user request to our system is being
I have to differentiate between an incoming request from an Iphone App and an
I have an incoming data stream that is being converted with XSLT v1.0 that
I have unpredictable frequency of Incoming csv data file which I need to store
I have a process that extracts customer info from multiple databases (MySql) based on
I have a process that extracts customer info from multiple databases (MySql) based on

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.