Skip to content

Instantly share code, notes, and snippets.

@thieux
Last active December 29, 2016 21:27
Show Gist options
  • Save thieux/0dc909c9c6dacbd2c4d046cf4090ad1d to your computer and use it in GitHub Desktop.
Save thieux/0dc909c9c6dacbd2c4d046cf4090ad1d to your computer and use it in GitHub Desktop.
(ns clojure-brave-true-exercises.crashcourse-test
(:require [clojure.test :refer :all]))
(deftest map-empty
(testing "empty"
(is (= #{} (mapset inc [])))))
(defn mapset [f list] #{})
(deftest map-singleton
(testing "singleton"
(is (= #{2} (mapset inc [1])))))
(defn mapset [f list]
(if (= list [])
#{}
#{2}))
(defn mapset [f list]
(if (= list [])
#{}
#{(inc 1)}))
(defn mapset [f list]
(if (= list [])
#{}
#{(inc (first list))}))
(defn mapset [f list]
(if (= list [])
#{}
#{(f (first list))}))
(defn mapset [f list]
(if (= list [])
#{}
(let [[head & tail] list]
(into #{(inc head)} #{}))))
(deftest map-dual
(testing "dual"
(is (= #{2 3} (mapset inc [1 2])))))
(defn mapset [f list]
(if (= list [])
#{}
(let [[head & tail] list]
(into #{(inc head)} (mapset f (into [] tail))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment