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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:57:10+00:00 2026-05-28T03:57:10+00:00

I am trying to pass the (lazy) sequence returned from a map operation to

  • 0

I am trying to pass the (lazy) sequence returned from a map operation to another map operation, so that I can look up elements in the first sequence. The code is parsing some football fixtures from a text file (in row/column format), cleaning it up, and then returning a map.

Here is the code:

(ns fixtures.test.lazytest
  (:require [clojure.string :as str])
  (:use [clojure.test]))

(defn- column-map
  "Produce map with column labels given raw data, return nil if not enough columns"
  [cols]
  (let [trimmed-cols (map str/trim cols)
        column-names {0 :fixture-type, 1 :division, 2 :home-team, 4 :away-team}]
    (if (> (count cols) (apply max (keys column-names)))
      (zipmap (vals column-names) (map trimmed-cols (keys column-names)))
      nil)))

(deftest test-mapping
  (let [cols '["L" "   Premier " "  Chelsea  " "v" "\tArsenal  "]
        fixture (column-map cols)]
    (is (= "Arsenal" (fixture :away-team)))
    (is (= "Chelsea" (fixture :home-team)))
    (is (= "Premier" (fixture :division)))
    (is (= "L" (fixture :fixture-type)))
  )
)

(run-tests 'fixtures.test.lazytest)

The approach I’m taking is:

  1. Clean up the vector of column data (remove leading/trailing spaces)
  2. Using zipmap, combine column name keywords with their corresponding element in the column data (note that not all columns are used)

The problem is, using the trimmed-cols in zipmap causes

java.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to clojure.lang.IFn

I think I know why this is happening … as trimmed-cols is a LazySeq, the map called from zipmap is objecting to receiving a non-function as its first argument.

To fix this I can change the let to:

trimmed-cols (vec (map str/trim cols))

But this doesn’t feel like the “best” option.

So:

  1. Is there a good general solution for using the result of a map operation as the “function” argument to another map?
  2. Is there a better approach for deriving a map of {: value} pairs from a vector of raw value data, where not all of the vector elements are used?

(I hesitate to ask for an idiomatic solution, but imagine somewhere there must be a generally accepted way of doing this.)

  • 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-28T03:57:11+00:00Added an answer on May 28, 2026 at 3:57 am

    I am not entirely sure what you’re after, but I can see why your code fails – like you said, trimmed-cols is not a function. Wouldn’t this simply work?

    I’m using :_dummy keys for columns that should be skipped. You can use as many as you like in the column-names vector: zipmap will merge them into one, which is removed by dissoc.

    (defn- column-map
      "Produce map with column labels given raw data, return nil if not enough columns"
      [cols]
      (let [trimmed-cols (map str/trim cols)
            column-names [:fixture-type :division :home-team :_dummy :away-team]]
        (if (>= (count cols) (count column-names))
          (dissoc (zipmap column-names trimmed-cols) :_dummy)
          nil)))
    
    (column-map ["L" "   Premier " "  Chelsea  " "v" "\tArsenal  "])
    ; => {:away-team "Arsenal", :home-team "Chelsea", :division "Premier", :fixture-type "L"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass one method to another in elisp, and then have that
I'm trying to pass a complex object (that can be serialized, if that helps)
I'm trying to pass a null value for the first parameter in the code
im trying to pass back from a user control a list of strings that
I'm trying to pass parameters from HTML-land to Flex-3 Flash-land, and can't seem to
I'm trying to pass data that is saved in sessionStorage from background.html to popup.html
When trying to pass a table built with HTML in my servlet like that:
Im trying to pass multiple things from a webpage inside a UIWebView back to
Im trying to pass some variables from the URL to the PHP script. Now
Iam trying to pass dynamic argument values i.e username from request using spring ioc.But

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.