Created
July 4, 2014 15:38
-
-
Save rockBreaker/cd53901946a659dacc8e to your computer and use it in GitHub Desktop.
WIP structerred data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns structured-data) | |
(defn do-a-thing | |
[x] | |
(let [xplus (+ x x)] | |
(Math/pow xplus xplus))) | |
(defn spiff | |
[v] | |
(+ (get v 0 0) (get v 2 0))) | |
(defn cutify [v] | |
(conj v "<3")) | |
(defn spiff-destructuring | |
[v] | |
(let [[x b c] v] | |
(+ x c))) | |
(defn point [x y] | |
[x y]) | |
(defn rectangle [bottom-left top-right] | |
[bottom-left top-right]) | |
(defn width | |
[rectangle] | |
(let [[[x1 y1] [x2 y2]] rectangle] | |
(- x2 x1))) | |
(defn height | |
[rectangle] | |
(let [[[x1 y1] [x2 y2]] rectangle] | |
(- y2 y1))) | |
(defn square? | |
[rectangle] | |
(= (width rectangle) (height rectangle))) | |
(defn area | |
[rectangle] | |
(* (width rectangle) (height rectangle))) | |
(defn contains-point? | |
[rectangle point] | |
(let [[[x1 y1] [x2 y2]] rectangle | |
[xp yp] point] | |
(and | |
(<= xp x2) | |
(>= xp x1) | |
(<= yp y2) | |
(>= yp y1)))) | |
(defn contains-rectangle? | |
[outer inner] | |
(let [[p1 p2] inner] | |
(and (contains-point? outer p1) (contains-point? outer p2))));returns true if inner is inside outer. | |
(defn title-length | |
[book] | |
(count (get book :title))) | |
(defn author-count | |
[book] | |
(count (get book :authors))) | |
(defn multiple-authors? | |
[book] | |
(> (author-count book) 1)) | |
(defn add-author | |
[book new-author] | |
(assoc book :authors (conj (book :authors) new-author))) | |
(defn alive? [author] | |
(not (number? (get author :death-year)))) | |
(defn element-lengths | |
[collection] | |
(map count collection)) | |
(defn second-elements | |
[collection] | |
(let [getsec (fn [coll] (get coll 1))] | |
(map getsec collection))) | |
(defn titles | |
[books] | |
(map :title books)) | |
(defn monotonic? | |
[a-seq] | |
(or (apply <= a-seq) (apply >= a-seq))) | |
(defn stars | |
[n] | |
(apply str (repeat n "*"))) | |
(defn toggle | |
[a-set elem] | |
(if (contains? a-set elem) (disj a-set elem) (conj a-set elem))) | |
(defn contains-duplicates? [a-seq] | |
(not (= | |
(count a-seq) | |
(count (set a-seq))))) | |
(defn old-book->new-book [book] | |
:-) | |
(defn has-author? [book author] | |
:-) | |
(defn authors [books] | |
:-) | |
(defn all-author-names [books] | |
:-) | |
(defn author->string [author] | |
:-) | |
(defn authors->string [authors] | |
:-) | |
(defn book->string [book] | |
:-) | |
(defn books->string [books] | |
:-) | |
(defn books-by-author [author books] | |
:-) | |
(defn author-by-name [name authors] | |
:-) | |
(defn living-authors [authors] | |
:-) | |
(defn has-a-living-author? [book] | |
:-) | |
(defn books-by-living-authors [books] | |
:-) | |
; %________% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment