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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:28:53+00:00 2026-06-15T20:28:53+00:00

Having a function which returns a seq of characters, I need to modify it

  • 0

Having a function which returns a seq of characters, I need to modify it to allow attaching metadata to some characters (but not all). Clojure doesn’t support ‘with-meta’ on primitive types. So, the possible options are:

  • return a seq of vectors of [character, metadata];

    pros: simplicity, data and metadata are tied together

    cons: need to extract data from vector

     

  • return two separate seqs, one for characters and one for metadata, caller most iterate those simultaneously if he cares about metadata;

    pros: caller is not forced to extract data from each stream element and may throw away meta-sequence if he wishes

    cons: need to iterate both seqs at once, more complexity on caller side if metadata is needed

     

  • introduce some record-wrapper containing one character and allowing to attach meta to itself (Clojure records implement IMeta);

    pros: data and metadata are tied together

    cons: need to extract data from record

     

  • your better option.

Which approach is better?

  • 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-15T20:28:55+00:00Added an answer on June 15, 2026 at 8:28 pm

    Using vector/map sequence, e.g.

    ({:char 'x' :meta <...>} {:char 'y' :meta <...>} {:char 'z' :meta <...>} ...)
    ; or
    (['x' <...>] ['y' <...>] ['z' <...>] ...)
    

    looks like the best option for me, that’s what I’d do myself if I had such task. Then, for example, writing a function which transforms such sequence back to sequence of chars is very simple:

    (defn characters [s] (map :char s))
    ; or
    (defn characters [s] (map first s))
    

    Iterating through characters and metadata at the same time is also very easy using destructuring bindings:

    (doseq [{:keys [char meta]} s] ...)
    ; or
    (doseq [[char meta] s] ...)
    

    What to use (map or vector) is mostly a matter of personal preference.

    IMO, using records and their IMeta interface is not quite as good: I think that this kind of metadata is mostly intended for language-related code (macros, code preprocessing, syntax extensions etc) and not for domain code. Of course I may be wrong in this assumption.

    And using two parallel sequences is the worst option because it is not as convenient for the user of your interface as single sequence. And throwing away the metadata is very simple with the function I wrote above, and it will not even have performance implications if all sequences are lazy.

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

Sidebar

Related Questions

I'm having a weird problem with the following function, which returns a string with
I am having a strange problem. I have a function which returns a large
Lambdaj (and some other similar libraries) provides a having function which allows me to
I am recently having one getter function which just returns the current Time using
I'm having a function which receives string parameters and convert them to integers. For
I am having a classes which have function to make random text and captcha
i'm having trouble trying to define this function-like macro, which takes 4 vector magnitudes
So the problem I'm having is I have a function which uses a variable
Given a function which returns an array; function return_me_an_array() { return array('my_value'); } How
We have a function used within our PHP/MySQL application which returns basic configuration information,

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.