{"size": 1784, "ext": "scrbl", "max_stars_repo_path": "private/variant.scrbl", "max_stars_repo_name": "dys-bigwig/rebellion", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "private/variant.scrbl", "max_issues_repo_name": "dys-bigwig/rebellion", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "private/variant.scrbl", "max_forks_repo_name": "dys-bigwig/rebellion", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.298245614, "max_line_length": 78, "alphanum_fraction": 0.6799327354}
#lang scribble/manual

@(require (for-label racket/base
                     racket/contract/base
                     rebellion/base/variant)
          (submod rebellion/private/scribble-evaluator-factory doc)
          scribble/example)

@(define make-evaluator
   (make-module-sharing-evaluator-factory
    #:public (list 'rebellion/base/variant)
    #:private (list 'racket/base)))

@title{Variants}
@defmodule[rebellion/base/variant]

A @deftech{variant} is a value tagged with a keyword. Variants are used to
distinguish different kinds of values by name, without knowing anything about
the types of those values.

@defproc[(variant? [v any/c]) variant?]{
 A predicate for @tech{variants}.}

@defproc[(variant [#:<kw> v any/c]) variant?]{
 Constructs a @tech{variant} containing @racket[v] tagged with the given
 keyword, where @racket[#:<kw>] stands for any keyword.

 @(examples
   #:eval (make-evaluator) #:once
   (variant #:success 42)
   (variant #:failure 'oops))}

@defproc[(variant-value [var variant?]) any/c]{
 Returns the value contained in @racket[var].

 @(examples
   #:eval (make-evaluator) #:once
   (variant-value (variant #:success 42))
   (variant-value (variant #:failure 'oops)))}

@defproc[(variant-tag [var variant?]) keyword?]{
 Returns the tag keyword of @racket[var].

 @(examples
   #:eval (make-evaluator) #:once
   (variant-tag (variant #:success 42))
   (variant-tag (variant #:failure 'oops)))}

@defproc[(variant-tagged-as? [var variant?] [tag-keyword keyword?]) boolean?]{
 Returns @racket[#t] if @racket[var] is tagged with @racket[tag-keyword],
 returns @racket[#f] otherwise.

 @(examples
   #:eval (make-evaluator) #:once
   (variant-tagged-as? (variant #:success 42) '#:success)
   (variant-tagged-as? (variant #:success 42) '#:failure))}
