Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 9, 2013 19:22
Show Gist options
  • Select an option

  • Save aamedina/6196395 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6196395 to your computer and use it in GitHub Desktop.
;; so what is stream fusion in a nutshell?
;; now that you have an intution for partial functions and composed functions, you now possess the intuition for stream fusion!
;; in category theory, mathematicians attempt to "categorize" all sorts of different "like" objects.
;; You're probably familiar with the notion of a Set in math. A set is an unordered and unique "bag" of elements.
(def my-set #{1 2 3})
#{1 2 3}
;; you can perform certain operations on sets.
(union my-set #{4 5 6})
#{1 2 3 4 5 6}
;; now remember, clojure values are immutable by default, so my-set (the var itself) is still pointing to #{1 2 3}, but this an aside.
(difference my-set #{1 2})
#{3}
(intersection my-set #{1})
#{1}
;; sets are a very useful category of objects because by categorizing them in such a way, every has certain useful properties.
;; we know that all elements in a set are unique, so we never have to worry about adding two things over again.
(union my-set #{2 3 4})
#{1 2 3 4}
;; By classifying mathematical constructs in such a way, we can make reasoning about them from a high level much easier.
;; But probably the most useful aspect of treating mathematical ideas this way is that it allows us to COMPARE different things.
;; For example, like Sets, Lists can also be viewed from a categorical lens.
;; Hence, we can compare how similar and dissimilar Lists and Sets are from one another.
;; well, for one - Lists are ordered.
(list 1 2)
(1 2)
;; and their order never changes, unless you create a new list. Sets are unordered, you cannot look up elements by index. There are no indices.
;; This makes things like "finding" objects really really simple from a high level.
(intersection my-set #{1})
#{1}
(intersection my-set #{4}))
#{}
;; You can't do this with lists. So, we know that sets are better to use when we don't care about order but we want an easy way to check for existence.
;; With lists, it makes keeping things order trivial.
;; Big Idea: We can reason about the properties of mathematical concepts in a more natural way when we classify them into categories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment