Literal values

Sets can be used as predicate functions returning true if the value is within the set

Checking valid playing cards

Define a namespace for the page and require Clojure Spec

  1. (ns practicalli.clojure
  2. (:require [clojure.spec.alpha :as spec]))
  1. (spec/valid? #{:club :diamond :heart :spade} :club)
  1. (spec/valid? #{:club :diamond :heart :spade} 42)

Answer to the ultimate question?

  1. (spec/valid? #{42} 42)

Using sets for literal values is similar to using the clojure.core/contains? function with a set collection type.

  1. (contains? #{:clubs :diamonds :hearts :spades} :hearts )