Commit ee7fd74c authored by Phil Jones's avatar Phil Jones

init

parents
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
This diff is collapsed.
# mtc-clj
A Clojure library designed to ... well, that part is up to you.
## Usage
FIXME
## License
Copyright © 2018 FIXME
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.
(defproject mtc-clj "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/data.finger-tree "0.0.3"]
])
(ns mtc-clj.core
(:require [clojure.spec.alpha :as s]
; [clojure.data.finger-tree :refer [double-list]]
)
)
(s/def ::MTC (s/coll-of string?))
(defn make-MTC [items]
(s/conform ::MTC items))
(defn next [mtc] (first mtc))
(defn tail [mtc] (rest mtc))
(defn add [mtc item] (lazy-seq (concat mtc (list item) )))
(defn add-first [mtc item] (cons item mtc))
(defn delay
([mtc] (lazy-seq (concat (tail mtc) (list (next mtc)))) )
([mtc n]
(let [x (next mtc)
as (take n (rest mtc))
zs (drop n (rest mtc))]
(lazy-seq (concat as (list x) zs)))) )
(defn done [mtc] (tail mtc))
(defn pull [mtc pattern]
(let [nf #(nil? (re-find (re-pattern pattern) %))
no-match (filter nf mtc )
match (filter #(not (nf %)) mtc )
]
(lazy-seq (concat match no-match))
))
(ns mtc-clj.core-test
(:require [clojure.test :refer :all]
[mtc-clj.core :refer :all]))
(deftest basic-queue
(testing "basic queue functions"
(let [mtc '("item 1" "item 2" "item 3")
mtc2 (add mtc "item 4")
mtc3 (add mtc2 "item 5")]
(is (= (count '()) 0))
(is (= (count mtc) 3))
(is (= (count mtc3) 5))
(is (= (next mtc) "item 1"))
(is (= (tail mtc) '("item 2" "item 3")))
(is (= mtc2 '("item 1" "item 2" "item 3" "item 4")))
(is (= mtc3 '("item 1" "item 2" "item 3" "item 4" "item 5")))
(is (= (add-first mtc "item 0") '("item 0" "item 1" "item 2" "item 3")))
(is (= (delay mtc) '("item 2" "item 3" "item 1")))
(is (= (done mtc) '("item 2" "item 3")))
) ))
(deftest defering
(testing "delay"
(let [mtc (range 10)]
(is (= (delay mtc 5) '(1 2 3 4 5 0 6 7 8 9) ))
)))
(deftest tags
(testing "+project tags"
(let [mtc (make-MTC '("hello" "teenage +america" "world" "team +america police"))]
(is (= (pull mtc #"\+america")
'("teenage +america" "team +america police" "hello" "world"))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment