Lets Talk more Clojure


Sets are simply a mathematical set, which means it retuns the no duplicates from a collection.

A collection such as the one below only returns the unique elements.

<br />(set '(1 1 1 2 2 2 3 3 3))

#{1 2 3}

To retrieve the union of two collections, you can use the union method.

(require 'clojure.set)

(set/union #{4 2 1} #{ 2 3 4 })

To get the intersection, unsurprisingly, we wuse the intersection method

(set/intersection #{1 2 3 4} #{2 3 5})

#{2 3}

Higher order functions

One of the aspects that I like about clojure is that it’s lisp and functional.

Which means we can write code like this.

((fn [f] (f 4 5)) *)

A function taking another function. Essential a higher order function, this I believe makes for some elegant code solutions.

I will talk more about this next time.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s