Wednesday, September 23, 2009

Uses for juxt

The juxtaposition operator can be used in parsing text.

Suppose we have the following text to process:

INSERT TEXT HERRE


Consider the following function which gets information from the clipboard

(defn bom-parser
  [part-num]
    (map (&
      (juxt last second (constantly part-num))
      (p split #"\s+")
      trim)
      ((& split-lines
        (p gsub #"\"" "")
        (p gsub #"NOT SHOWN" ""))
      (get-clip))))


In the mapping operation you can see a call to juxt. This helps turn a block of text into a list of vectors.

No comments:

Post a Comment