Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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
- data StreamEnv m
- createStreamEnv :: Monad m => PlayerCount -> StreamEnv m
- withGetStandings :: (Focus -> m Standings) -> StreamEnv m -> StreamEnv m
- noStandings :: Monad m => Focus -> m Standings
- data Tourney m = Tourney {
- tourneyStream :: StreamM m (MatchStream m) ()
- tourneyStreamEnv :: StreamEnv m
- type TourneyStream m = StreamM m (StreamM m (Compiled (Sorter, StreamM m (Compiled Match) ())) ()) ()
- data CompileError
- = InvalidMatch { }
- | InvalidFocus { }
- type Compiled = Either (NonEmpty CompileError)
- createTourney :: forall m a. Monad m => StreamEnv m -> Tournament a -> Tourney m
- runTourney :: Monad m => Tourney m -> TourneyStream m
- newtype RoundStream m = RoundStream {
- unRoundStream :: StreamEnv m -> StreamM m (Tournament TOne) ()
- createRoundStream :: forall m a. Monad m => Tournament a -> RoundStream m
- newtype MatchStream m = MatchStream {}
- createMatchStream :: forall m. Monad m => Tournament TOne -> MatchStream m
- data Inspection t m a = Inspection {
- standingsFn :: Focus -> m Standings
- playerCount :: PlayerCount
- query :: Inspect t a
- data Inspect (t :: Depth) a where
- runInspection :: Monad m => Inspection t m a -> Tournament t -> m a
- pureMatchesByRound :: Tournament TMany -> PlayerCount -> MapByRound (MapByMatches (Maybe Result))
Compilation
Creating a compiler environment
Instances
Generic (StreamEnv m) Source # | |
type Rep (StreamEnv m) Source # | |
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))) |
createStreamEnv :: Monad m => PlayerCount -> StreamEnv m Source #
Main compilation functions
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 | |
InvalidFocus | |
Instances
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
.
runTourney :: Monad m => Tourney m -> TourneyStream m Source #
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 | |
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 | |
Fields
|
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
pureMatchesByRound :: Tournament TMany -> PlayerCount -> MapByRound (MapByMatches (Maybe Result)) Source #