journeyman-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Tourney.Stream

Description

This module defines ways to create streams of matches from tournaments.

Since tournaments depend on results that may not be available immediately, the types for the streams here get quite complex. This is so that the streams are able to expose all the matches that are purely available, that is all the matches and rounds that can be extracted from a tournament immediately without having any results. For most tournaments, this is probably all matches, but some tournament styles may not have this property, such as Swiss-style.

At the same time, I try to validate that the tournament is valid namely that no focus is set that is not within the outer/current focus, and that no match uses slots that are not in the current focus.

How this works

The core operation that enables the transformation of arbitrarily nested and unbalanced combinations of Overlay and Sequence is alignment. Effectively, every occurence of Overlay triggers an alignment operation such that both sides are balanced.

These diagrams may help elucidate how this is possible:

Here, an unbalanced combination of overlays and interleaves is turned into a balanced sequence of overlays by successively re-balancing the tournament tree.

Synopsis

Compilation

Creating a compiler environment

data StreamEnv m Source #

Instances

Instances details
Generic (StreamEnv m) Source # 
Instance details

Defined in Tourney.Stream

Associated Types

type Rep (StreamEnv m) :: Type -> Type Source #

Methods

from :: StreamEnv m -> Rep (StreamEnv m) x Source #

to :: Rep (StreamEnv m) x -> StreamEnv m Source #

type Rep (StreamEnv m) Source # 
Instance details

Defined in Tourney.Stream

type Rep (StreamEnv m) = D1 ('MetaData "StreamEnv" "Tourney.Stream" "journeyman-0.1.0.0-inplace" 'False) (C1 ('MetaCons "StreamEnv" 'PrefixI 'True) (S1 ('MetaSel ('Just "getStandings") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Focus -> m Standings)) :*: S1 ('MetaSel ('Just "focus") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Focus)))

Main compilation functions

data Tourney m Source #

A fully compiled Tournament that has been transformed into a stream of matches. The mnemonic for the name here is that the word "tourney" is a smaller synonym of "tournament".

Constructors

Tourney 

Fields

type TourneyStream m = StreamM m (StreamM m (Compiled (Sorter, StreamM m (Compiled Match) ())) ()) () Source #

A stream of 1. Rounds, which are streams of 2. Match groups, which are sorters (a Focus and SortMethod), and streams of 3. Matches

data CompileError Source #

Constructors

InvalidMatch 

Fields

InvalidFocus 

Fields

Instances

Instances details
Generic CompileError Source # 
Instance details

Defined in Tourney.Stream

Associated Types

type Rep CompileError :: Type -> Type Source #

Show CompileError Source # 
Instance details

Defined in Tourney.Stream

Eq CompileError Source # 
Instance details

Defined in Tourney.Stream

Ord CompileError Source # 
Instance details

Defined in Tourney.Stream

type Rep CompileError Source # 
Instance details

Defined in Tourney.Stream

type Rep CompileError = D1 ('MetaData "CompileError" "Tourney.Stream" "journeyman-0.1.0.0-inplace" 'False) (C1 ('MetaCons "InvalidMatch" 'PrefixI 'True) (S1 ('MetaSel ('Just "focus") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Focus) :*: S1 ('MetaSel ('Just "match") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Match)) :+: C1 ('MetaCons "InvalidFocus" 'PrefixI 'True) (S1 ('MetaSel ('Just "outer") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Focus) :*: S1 ('MetaSel ('Just "inner") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Focus)))

type Compiled = Either (NonEmpty CompileError) Source #

A value that has gone through a compiler; either the compiled thing, or an error. Convenience type

createTourney :: forall m a. Monad m => StreamEnv m -> Tournament a -> Tourney m Source #

Compile a tournament into a Tourney.

newtype RoundStream m Source #

A tournament is that has been compiled into a stream of rounds

Constructors

RoundStream 

Fields

createRoundStream :: forall m a. Monad m => Tournament a -> RoundStream m Source #

Compile a tournament into a stream of rounds.

Compile a tournament into a stream of rounds.

Since we have paramaterised Tournament by number of rounds, forcing it to be TOne ensures that each individual tournament is only one round. Meanwhile, since the structure of a stream does not allow for two rounds to yield into the same round index, each individual round is unique.

In order to accomplish this, we just need to know upfront the PlayerCount, and also a way to stream results in.

newtype MatchStream m Source #

A round of a tournament that has been compiled into a stream of matches, grouped by their sorting method

Constructors

MatchStream 

Fields

createMatchStream :: forall m. Monad m => Tournament TOne -> MatchStream m Source #

Create a stream of matches from a round of a tournament. (Note that Tournament 1 indicates a single round)

Inspection

data Inspection t m a Source #

Constructors

Inspection 

runInspection :: Monad m => Inspection t m a -> Tournament t -> m a Source #

Inspect a tournament

Useful for builders that somehow compose with another builder's matches