~subsetpark/whist

ref: b0f715a90af4b24daa3c892ceb00f7eb78478281 whist/players.janet -rw-r--r-- 555 bytes
b0f715a9 — Zach Smith Add some explanatory text 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## players.janet
(defn next-player
  [id players &opt out-of]
  
  (var ind (find-index |(and (= ($0 :id) id)) players))
  (let [f (fiber/new (fn []
		       (while true
			 (do
			   (set ind (mod (inc ind) (length players)))
			   (yield ind)))))]
    (var found nil)
    (while (not found)
      (let [new-ind (resume f)
	    new-id ((players new-ind) :id)]
	(if (or (nil? out-of) (in out-of (keyword new-id)))
	  (set found new-id))))
    found))

(defn of-team [players team] (->> players
				  (filter |(= ($0 :team) team))
				  (map |($0 :id))))