ofc-calc-haskell-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

CardParts.Cards

Description

Combined (value + suit) card data type and its processing functions

Synopsis

Documentation

data Card Source #

This type represents a card - combination of suit and value.

Constructors

Card 

Fields

Instances

Instances details
Eq Card Source # 
Instance details

Defined in CardParts.Cards

Methods

(==) :: Card -> Card -> Bool #

(/=) :: Card -> Card -> Bool #

Ord Card Source # 
Instance details

Defined in CardParts.Cards

Methods

compare :: Card -> Card -> Ordering #

(<) :: Card -> Card -> Bool #

(<=) :: Card -> Card -> Bool #

(>) :: Card -> Card -> Bool #

(>=) :: Card -> Card -> Bool #

max :: Card -> Card -> Card #

min :: Card -> Card -> Card #

Show Card Source # 
Instance details

Defined in CardParts.Cards

Methods

showsPrec :: Int -> Card -> ShowS #

show :: Card -> String #

showList :: [Card] -> ShowS #

Generic Card Source # 
Instance details

Defined in CardParts.Cards

Associated Types

type Rep Card :: Type -> Type #

Methods

from :: Card -> Rep Card x #

to :: Rep Card x -> Card #

FromJSON Card Source # 
Instance details

Defined in CardParts.Cards

Methods

parseJSON :: Value -> Parser Card

parseJSONList :: Value -> Parser [Card]

ToJSON Card Source # 
Instance details

Defined in CardParts.Cards

Methods

toJSON :: Card -> Value

toEncoding :: Card -> Encoding

toJSONList :: [Card] -> Value

toEncodingList :: [Card] -> Encoding

type Rep Card Source # 
Instance details

Defined in CardParts.Cards

type Rep Card = D1 ('MetaData "Card" "CardParts.Cards" "ofc-calc-haskell-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Card" 'PrefixI 'True) (S1 ('MetaSel ('Just "value") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value) :*: S1 ('MetaSel ('Just "suit") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Suit)))

parseCard :: String -> Either String Card Source #

This function gets a string which represents full card combination (value + suit) and returns a Card wrapped with Right. The function uses parseValue and parseSuit functions.

Passed string should have length 2 and have format "{VALUE}{SUIT}".

Examples:

parseCard "2c" = Right Two Clubs
parseCard "As" = Right Ace Spades
parseCard "" = Left "Can't process emtpy string"
parseCard "22c" = Left "Argument length should be 2"
parseCard Zd = Left "There is no broadway card, which could be represented with 'Z'"
parseCard "5f" = Left "There is no card suit marked as 'f'"
parseCard "2x" = Left "There is no card suit marked as 'x'"