open:thread-first

thread-first

thread-first -> is ideal for navigating large, nested structures.

(-> results
    :matches
    (nth 3)
    :scores
    (get "total_points"))

This works with Java objects too

(-> results
    .getMatches
    (nth 3)
    .getScores
    (.getKey "total_points"))

The second use case of -> is performing a series of functional transformations on a single value:

(-> username
    string/trim
    string/lower-case
    (string/replace #"[^a-z]" "-"))

(-> game-state
    (assoc :next-player :player2)
    (update :turn-counter inc)
    (update-in [:scores :player1] + 10)
    (update-in [:scores :player2] - 3))

  • open/thread-first.txt
  • Last modified: 2024/10/05 06:15
  • by 127.0.0.1