Some quick Clojure scripts I’m collecting. Also, for something of this I’m looking at Bob Martin’s Spacewars program.

; Working with drop-while
(drop-while empty? ["" [] "foobar" nil])
=> ("foobar" nil)

; This works left to right...
(drop-while empty? ["" [] nil "foobar"  ])
=> ("foobar")



(empty? [nil] )
=> false


(empty? nil)
=> true

(vec (sort (set [1 2 2 3])))
=> [1 2 3]


(distinct [1 2 2 3])
=> (1 2 3)


; These two kind of go together
(map-indexed vector [1 nil 3 nil])
=> ([0 1] [1 nil] [2 3] [3 nil])

; Here it gets filtered out..
(filter #(nil? (second %))
        (map-indexed vector [1 nil 3 nil])
        )
=> ([1 nil] [3 nil])


(defprotocol MyProtocol
  (-f0 [this args]))

(defn f0 [this & args]
  (-f0 this args))

(defn -f0 [this & args]
  (filter this (flatten args) )
  )

; (f0 odd? 1 2 3 4)
;=> (1 3)
;
;