Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

provide scala.Numeric + Range for enumerations? #145

Open
bishabosha opened this issue Oct 18, 2020 · 2 comments
Open

provide scala.Numeric + Range for enumerations? #145

bishabosha opened this issue Oct 18, 2020 · 2 comments

Comments

@bishabosha
Copy link
Member

bishabosha commented Oct 18, 2020

from https://twitter.com/ppurang/status/1317827002070597634

enum Rank {
  case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace 
}

enum Suit {
  case  Clubs, Diamonds, Hearts, Spades
}

case class Card(suit: Suit, rank: Rank)

import Rank._
import Suit._

val Deck = for {
  suit <- Clubs to Spades
  rank <- Two to Ace
} yield Card(suit, rank)

alternative: a third party library could do this with derivation

@bishabosha bishabosha changed the title provide scala.Numeric for enumerations? provide scala.Numeric + Range for enumerations? Oct 18, 2020
@bishabosha
Copy link
Member Author

bishabosha commented Oct 18, 2020

alternatively, a method that just provides an iterator in the order given - then is this specialised given that there is no automatic ordering for enumerations

@bishabosha
Copy link
Member Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant