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

  • Home
  • SEARCH
  • 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 8234913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:38:16+00:00 2026-06-07T18:38:16+00:00

I am working in clojure with a java class which provides a retrieval API

  • 0

I am working in clojure with a java class which provides a retrieval API for a domain specific binary file holding a series of records.

The java class is initialized with a file and then provides a .query method which returns an instance of an inner class which has only one method .next, thus not playing nicely with the usual java collections API. Neither the outer nor inner class implements any interface.

The .query method may return null instead of the inner class. The .next method returns a record string or null if no further records are found, it may return null immediately upon the first call.

How do I make this java API work well from within clojure without writing further java classes?

The best I could come up with is:


(defn get-records
  [file query-params]
  (let [tr (JavaCustomFileReader. file)]
    (if-let [inner-iter (.query tr query-params)] ; .query may return null                                                               
      (loop [it inner-iter
             results []]
       (if-let [record (.next it)]
         (recur it (conj results record))
         results))
      [])))

This gives me a vector of results to work with the clojure seq abstractions. Are there other ways to expose a seq from the java API, either with lazy-seq or using protocols?

  • 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-07T18:38:17+00:00Added an answer on June 7, 2026 at 6:38 pm

    Without dropping to lazy-seq:

    (defn record-seq
      [q]
      (take-while (complement nil?) (repeatedly #(.next q))))
    

    Instead of (complement nil?) you could also just use identity if .next does not return boolean false.

    (defn record-seq
      [q]
      (take-while identity (repeatedly #(.next q))))
    

    I would also restructure a little bit the entry points.

    (defn query
      [rdr params]
      (when-let [q (.query rdr params)]
        (record-seq q)))
    
    (defn query-file
      [file params]
      (with-open [rdr (JavaCustomFileReader. file)]
        (doall (query rdr params))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Clojure, but I can read Java, so this isn't a Clojure specific
I'm working on implementing an infix-calculator in Clojure, which starts with me implementing Dijkstra's
I'm working on some Clojure code, in which I have a tree of entities
I'm working through the Clojure examples in Stuart Halloway's Programmming Clojure and I've hit
Working on the problems on Project Euler to try to learn Clojure. I'm on
I've been working on a web app in Clojure as a side project, and
Working with an undisclosed API, I found a function that can set the number
everyone, I've started working yesterday on the Euler Project in Clojure and I have
For some reason I can't get clojure REPL working with jline, what i did
I'm attempting to write a library to do some domain-specific stuff. I'd like to

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.