Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Halfway there. #528

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: clojure
dist: precise
lein: lein2
script: lein2 midje :config .midje-grading-config.clj
jdk:
Expand Down
52 changes: 38 additions & 14 deletions src/one_function_to_rule_them_all.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
(ns one-function-to-rule-them-all)

(defn concat-elements [a-seq]
:-)
(reduce concat [] a-seq))

(defn str-cat [a-seq]
:-)
(if (empty? a-seq)
""
(reduce (fn [b-seq x] (str b-seq " " x)) a-seq)))

(defn my-interpose2 [x a-seq]
(if (empty? a-seq)
[]
(reduce (fn [b-seq y] (conj b-seq x y)) a-seq)))

(defn my-interpose [x a-seq]
[:-])
(cond
(empty? a-seq)
[]
(= 1 (count a-seq))
a-seq
:else
(reduce (fn [b-seq y] (conj b-seq x y)) a-seq)))

(defn my-count [a-seq]
:-)
(let [counter (fn [count e]
(if e (inc count) count))]
(reduce counter 0 a-seq)))

(defn my-reverse [a-seq]
[:-])
(if (empty? a-seq)
[]
(reduce cons a-seq)))

(defn min-max-element [a-seq]
[:-])
Expand All @@ -27,17 +44,24 @@
(defn parity [a-seq]
[:-])

(defn minus [x]
:-)
(defn minus
([x] (* -1 x))
([x y] (- x y)))

(defn count-params [x]
:-)
(defn count-params [& more]
(count more))

(defn my-* [x]
:-)
(defn my-*
([] 1)
([x] x)
([x y] (* x y))
([x y & more] (reduce * (* x y) more)))

(defn pred-and [x]
(fn [x] :-))
(defn pred-and
([] (fn [a] a))
([x] (fn [a] (x a)))
([x y] (fn [a] (and (x a) (y a))))
([x y & more] (reduce (fn [a] (and (x a) (y a))) more)))

(defn my-map [f a-seq]
[:-])
[:-])