开发者

taking top fifty items in sorted vector into another vector (clojure)

开发者 https://www.devze.com 2023-02-28 13:25 出处:网络
EDITED because question is about same program. I\'m trying to take the top fifty items in the first vector and write them to the topfifty variable, to return to use elsewhere.

EDITED because question is about same program.

I'm trying to take the top fifty items in the first vector and write them to the topfifty variable, to return to use elsewhere.

 "gets the开发者_运维问答 closest 50 locations in the file fName and writes them out by sending a function     to the agent"
  [fName]
  (let [sorted (sort-by sortFn (makeStructs fName))
        topFifty ;TODO take the top 50 from sorted 
        ]

How exactly do I do this in clojure? I'm new to the language and have never used lisp. I'd rather not use a for loop as that is not exactly functional-ish.


To answer the new question (the question that my other answer was in response to has been replaced): (take 50 sorted) will return the first 50 elements of sorted.


You probably want something like (apply struct storeinfo vals), where vals is the result of your split. This unpacks all of the values in vals into a call to (struct storeinfo ...), which creates a storeinfo from initial values in the same order as its definition.

0

精彩评论

暂无评论...
验证码 换一张
取 消