How can I type check this function?

24 views
Skip to first unread message

Didier

unread,
Apr 28, 2017, 7:42:01 AM4/28/17
to core.typed
(defn drop-every-n-items
  "Takes a vector, and returns a vector with every n'th items removed."
  [vec :- Vec n :- Int] :- Vec
  (if (infix n <= 0)
    []
    (into [] (mapcat #(take (dec n) %) (partition-all n vec)))))

I'd like to properly type check this, and I just can't figure it out.

Ambrose Bonnaire-Sergeant

unread,
Apr 28, 2017, 7:44:35 AM4/28/17
to core.typed
Untested, try this.

(ann drop-every-n-times (t/All [a] [(t/Vec a) Int -> (t/Vec a)]))
(defn drop-every-n-items
  "Takes a vector, and returns a vector with every n'th items removed."
  [vec n]
  (if (infix n <= 0)
    []
    (into [] (mapcat (t/fn [e :- (t/Vec a)] (take (dec n) e)) (partition-all n vec)))))

Reply all
Reply to author
Forward
0 new messages