3 ms·
I actually had something similar a couple of weeks ago. My initial model was just: val cards = for { rank <- 'a, '2, [...], 'j, 'q, 'k suit <- 'h, 'c
by hythloday 13y ago
I actually had something similar a couple of weeks ago. My initial model was just:
val cards = for {
rank <- 'a, '2, [...], 'j, 'q, 'k
suit <- 'h, 'c, 'd, 's
} yield (rank, suit)
val deck = scala.util.Random.shuffle(cards)
which gives you something to play with to validate your model. It's not an api I'd choose to publish, of course, there are many better type-safe ones written here, though I'm sad none of them have used Unicode for suits (I know someone working on a dating app who used a method called ❤ to compare two users: so something like "if (sappho ❤ rhodopis > 95) { ... }")
But my point is that Scala gives you the option, and is tolerant, of working in this slightly dirty way, and then lets you clean it up (and a type-safe compiler will flag up where you are using your old api). I don't know clojure well enough, so, what's the similar workflow there?
- ellicottvilleny 13y agoSo some developers will love type-systems, and some will prefer to stay in Lisp-land forever. :-) The OP seems to be a lisp hacker at heart, and Clojure is the batteries-included Lisp du "jure". (sic)