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
  • 마지막으로 수정됨: 2022/02/25 13:13
  • 저자 127.0.0.1