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

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

Answer to the ultimate question?

(spec/valid? #{42} 42)

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

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

results matching ""

    No results matching ""