Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Last active November 28, 2016 01:59
Show Gist options
  • Save ympbyc/268322cf21a1a2e5d478 to your computer and use it in GitHub Desktop.
Save ympbyc/268322cf21a1a2e5d478 to your computer and use it in GitHub Desktop.
It worked!
(ns cljs.core.typed.test.ympbyc.cljs-core
(:require-macros [cljs.core.typed :refer [ann] :as ct])
(:require [cljs.core.typed :refer [All U IFn]]
[cljs.core :refer [IVector ISeq]]))
(ann cljs.core/seq (All [x] [(U (ISeq x) (IVector x)) -> (ISeq x)]))
(ann cljs.core/first
(All [x] [(U (ISeq x) (IVector x)) -> (U nil x)]))
;;(ann cljs.core/second ) ...etc...
(ann cljs.core/rest (All [x]
[(U (ISeq x) (IVector x)) -> (ISeq x)]))
(ann cljs.core/last (All [x]
[(U (ISeq x) (IVector x)) -> (U nil x)]))
(ann cljs.core/butlast (All [x]
[(U (ISeq x) (IVector x)) -> (ISeq x)]))
;;first
(ann vec-fst (U nil number))
(def vec-fst (first [8]))
(ann seq-fst (U nil number))
(def seq-fst (first (seq [1 2 3])))
(ann fst-nil (U nil number))
(def fst-nil (first []))
;;rest
(ann vec-rest (ISeq number))
(def vec-rest (rest [1 2 3]))
(ann seq-rest (ISeq number))
(def seq-rest (rest (seq [1 2 3])))
(ann rest-empty (ISeq nil))
(def rest-empty (rest []))
;;last
(ann vec-last (U nil number))
(def vec-last (last [1 2 3]))
(ann seq-last (U nil number))
(def seq-last (last (seq [1 2 3])))
(ann last-nil (U nil number))
(def last-nil (last []))
;;butlast
(ann vec-butlast (ISeq number))
(def vec-butlast (butlast [1 2 3]))
(ann seq-butlast (ISeq number))
(def vec-butlast (butlast (seq [1 2 3])))
(ann butlast-empty (ISeq nil))
(def butlast-empty (butlast []))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment