# Collections
How to ....?
- declare?
- add to?
- remove from?
- check is exists?
- merge into?
- can they nest?
# Sets
just like maths, unordered with no duplicates
(def players #{"Alice", "Bob", "Kelly"})
(conj players "Fred")
(disj players "Bob" "Sal")
(contains? players "Kelly")
Merge one collection INTO another collection?
(def players #{"Alice" "Bob" "Kelly"})
(def new-players ["Tim" "Sue" "Greg"])
(into players new-players)
# Hased Maps | Maps
operation | sets | maps |
---|---|---|
declare | def #{} | def {} |
add to | conj | assoc |
remove | disj | dissoc |
lookup | contains? | get , contains? |
sub | keys , vals | |
merging | into | merge |
sorted | sorted-map |
- Look up with a default, assign default values if not found
- great for representing Domain Objects
- Use
Records
for polymorphic behaviour, OO styled interfacesprotocols
statements vs expressions
expressions return values, whereas statements do not
# Programming Styles
- Use
do
blocks withif
only if your bodies have side effects! (Why?)
# Branching / Conditional Flow
using
if
andif do
when
cond
andelse
Whats the difference b/w
if
andwhen
?
if - handle both trythy and falsey Branching. Side-effects in do
block
when - only when truthy cndition has to be handleded