deck

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 4 Imported by: 0

README

code quality tools codecov Go Report Card

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Suits = []Suit{Spade, Diamond, Club, Heart}

Functions

func Draw

func Draw(amount int) func(cards []Card) ([]Card, []Card)

Draw removes the given amount of cards from the end and returns it as the first return value. The second return value are the remaining cards in the deck.

func Filter

func Filter(f func(Card) bool) func([]Card) []Card

Filter applies the given filter to the deck and returns it. Can be used as an option when creating a deck using New.

func Less added in v1.1.0

func Less(cards []Card) func(i, j int) bool

Less sorts the cards ascending by their corresponding rank

func Sort added in v1.1.0

func Sort(less func(cards []Card) func(i, j int) bool) func([]Card) []Card

Sort takes a less function and applies it to the cards. Can be used as an option when creating a deck using New.

func WithDecks added in v1.4.0

func WithDecks(amount int) func([]Card) []Card

WithDecks puts the given amount of decks in a deck (52 * amount). Can be used as an option when creating a deck using New.

func WithJokers added in v1.4.0

func WithJokers(amount int) func([]Card) []Card

WithJokers puts the passed amount of jokers, with the Suit Joker, in the deck without a Rank. Can be used as an option when creating a deck using New.

Types

type Card

type Card struct {
	Suit Suit
	Rank Rank
}

func DefaultSort added in v1.1.0

func DefaultSort(cards []Card) []Card

DefaultSort sorts the cards using the Less function Can be used as an option when creating a deck using New.

func New

func New(opts ...func([]Card) []Card) []Card

New creates a new 52 card deck using the default Suits Spade, Diamond, Club and Heart Can take options to configure it as desired.

func Shuffle

func Shuffle(cards []Card) []Card

Shuffle randomizes the deck. Can be used as an option when creating a deck using New.

func (Card) Is

func (c Card) Is(rank Rank, suit Suit) bool

Is checks if a card is a specific card by checking Rank and Suit.

func (Card) String

func (c Card) String() string

type Rank

type Rank int
const (
	Ace Rank
	Two
	Three
	Four
	Five
	Six
	Seven
	Eight
	Nine
	Ten
	Jack
	Queen
	King
)

func (Rank) String

func (i Rank) String() string

type Suit

type Suit int
const (
	Spade Suit = iota
	Club
	Diamond
	Heart
	Joker
)

func (Suit) String

func (i Suit) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL