- README

- Top Level Namespace
- Adler32
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- CRC32
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - Subtle
- Crystal
  - Macros
    - And
    - Arg
    - ArrayLiteral
    - Assign
    - ASTNode
    - BinaryOp
    - Block
    - BoolLiteral
    - Call
    - Case
    - Cast
    - CharLiteral
    - ClassDef
    - ClassVar
    - Def
    - Expressions
    - Generic
    - Global
    - HashLiteral
    - If
    - ImplicitObj
    - InstanceSizeOf
    - InstanceVar
    - IsA
    - Macro
    - MacroId
    - MetaVar
    - MultiAssign
    - NamedArgument
    - NamedTupleLiteral
    - NilableCast
    - NilLiteral
    - Nop
    - Not
    - NumberLiteral
    - Or
    - Out
    - Path
    - PointerOf
    - RangeLiteral
    - ReadInstanceVar
    - RegexLiteral
    - Require
    - RespondsTo
    - SizeOf
    - Splat
    - StringInterpolation
    - StringLiteral
    - SymbolLiteral
    - TupleLiteral
    - TypeDeclaration
    - TypeNode
    - UnaryExpression
    - UninitializedVar
    - Union
    - Var
    - VisibilityModifier
    - When
    - While
  - System
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - Abbrev
      - Attribute
    - AT
    - FORM
    - Info
      - Value
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
    - Strings
    - TAG
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - Base
  - MD5
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Flate
  - Error
  - Reader
  - Strategy
  - Writer
- Float
  - Primitive
  - Printer
    - CachedPowers
      - Power
    - DiyFP
    - Grisu3
    - IEEE
- Float32
- Float64
- GC
  - Stats
- Gzip
  - Error
  - Header
  - Reader
  - Writer
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - CompressHandler
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - ErrorHandler
  - FormData
    - Builder
    - Error
    - FileMetadata
    - Parser
    - Part
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Multipart
    - Builder
    - Error
    - Parser
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - Builder
    - ArrayState
    - DocumentEndState
    - DocumentStartState
    - ObjectState
    - StartState
    - State
  - Error
  - Lexer
  - ParseException
  - Parser
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - AttributeIndex
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DIFlags
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModuleFlag
  - ModulePassManager
  - OperandBundleDef
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
    - Kind
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - DigestIO
    - DigestMode
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - ISAAC
  - MT19937
  - PCG32
  - System
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Reflect
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- WeakRef
- XML
  - Attributes
  - AttributeType
  - Builder
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Builder
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zip
  - CompressionMethod
  - Error
  - File
    - Entry
  - FileInfo
  - Reader
    - Entry
  - Writer
    - Entry
- Zlib
  - Error
  - Reader
  - Writer

# struct StaticArray(T, N)

- StaticArray(T, N)
- Value
- Object

## Overview

A fixed-size, stack allocated array.

## Included Modules

- Indexable(T)

## Defined in:

## Constructors

- .new(&block : Int32 -> T)

  Creates a new static array and invokes the block once for each index of the array, assigning the block's value in that index.

- .new(value : T)

  Creates a new static array filled with the given value.

## Instance Method Summary

- #==(other : StaticArray)

  Equality.

- #==(other)

  Equality with another object.

- #[]=(index : Int, value : T)

  Sets the given value at the given index.

- #[]=(value : T)

  Fills the array by substituting all elements with the given value.

- #clone

  Returns a new `StaticArray` where each element is cloned from elements in `self`.

- #map!(&block)

  Invokes the given block for each element of `self`, replacing the element with the value returned by the block.

- #map_with_index!(&block : T, Int32 -> T)

  Like `map`, but the block gets passed both the element and its index.

- #pretty_print(pp)
- #reverse!

  Reverses the elements of this array in-place, then returns `self`.

- #shuffle!(random = Random::DEFAULT)

  Modifies `self` by randomizing the order of elements in the array using the given random number generator.

- #size

  Returns the size of `self`

- #to_s(io : IO)

  Appends a string representation of this static array to the given `IO`.

- #to_slice

  Returns a slice that points to the elements of this static array.

- #to_unsafe : Pointer(T)

  Returns a pointer to this static array's data.

- #unsafe_at(index : Int)
- #update(index : Int, &block)

  Yields the current element at the given index and updates the value at the given index with the block's value.

## Macro Summary

- [](*args)

  Create a new `StaticArray` with the given args.

### Instance methods inherited from module `Indexable(T)`

[](index : Int) [], []?(index : Int) []?, at(index : Int, &block)
at(index : Int) at, bsearch(&block) bsearch, bsearch_index(&block) bsearch_index, each(&block)
each each, each_index(&block) : Nil
each_index each_index, empty? empty?, equals?(other : Indexable, &block)
equals?(other, &block) equals?, first(&block)
first first, first? first?, hash hash, index(object, offset : Int = 0)
index(offset : Int = 0, &block) index, last
last(&block) last, last? last?, reverse_each(&block) : Nil
reverse_each reverse_each, rindex(offset = size - 1, &block)
rindex(value, offset = size - 1) rindex, sample(random = Random::DEFAULT) sample, size size, unsafe_at(index : Int) unsafe_at, values_at(*indexes : Int) values_at, zip(other : Indexable, &block)
zip(other : Indexable(U)) forall U zip, zip?(other : Indexable, &block)
zip?(other : Indexable(U)) forall U zip?

### Instance methods inherited from module `Enumerable(T)`

all?(&block)
all? all?, any?(&block)
any? any?, chunks(&block : T -> U) forall U chunks, compact_map(&block) compact_map, count(&block)
count(item) count, cycle(n, &block)
cycle(&block) cycle, each(&block : T -> _) each, each_cons(count : Int, reuse = false, &block) each_cons, each_slice(count : Int, reuse = false, &block) each_slice, each_with_index(offset = 0, &block) each_with_index, each_with_object(obj, &block) each_with_object, find(if_none = nil, &block) find, first(count : Int)
first first, first? first?, flat_map(&block : T -> Array(U) | Iterator(U) | U) forall U flat_map, grep(pattern) grep, group_by(&block : T -> U) forall U group_by, in_groups_of(size : Int, filled_up_with : U = nil) forall U
in_groups_of(size : Int, filled_up_with : U = nil, reuse = false, &block) forall U in_groups_of, includes?(obj) includes?, index(&block)
index(obj) index, index_by(&block : T -> U) forall U index_by, join(separator, io)
join(separator = "")
join(separator, io, &block)
join(separator = "", &block) join, map(&block : T -> U) forall U map, map_with_index(&block : T, Int32 -> U) forall U map_with_index, max max, max? max?, max_by(&block : T -> U) forall U max_by, max_by?(&block : T -> U) forall U max_by?, max_of(&block : T -> U) forall U max_of, max_of?(&block : T -> U) forall U max_of?, min min, min? min?, min_by(&block : T -> U) forall U min_by, min_by?(&block : T -> U) forall U min_by?, min_of(&block : T -> U) forall U min_of, min_of?(&block : T -> U) forall U min_of?, minmax minmax, minmax? minmax?, minmax_by(&block : T -> U) forall U minmax_by, minmax_by?(&block : T -> U) forall U minmax_by?, minmax_of(&block : T -> U) forall U minmax_of, minmax_of?(&block : T -> U) forall U minmax_of?, none?(&block)
none? none?, one?(&block) one?, partition(&block) partition, product(&block)
product(initial : Number, &block)
product
product(initial : Number) product, reduce(&block)
reduce(memo, &block) reduce, reject(&block : T -> ) reject, select(&block : T -> ) select, size size, skip(count : Int) skip, skip_while(&block) skip_while, sum(initial)
sum
sum(initial, &block)
sum(&block) sum, take_while(&block) take_while, to_a to_a, to_h to_h, to_set to_set

### Instance methods inherited from module `Iterable(T)`

chunk(reuse = false, &block : T -> U) forall U chunk, cycle(n)
cycle cycle, each each, each_cons(count : Int, reuse = false) each_cons, each_slice(count : Int, reuse = false) each_slice, each_with_index(offset = 0) each_with_index, each_with_object(obj) each_with_object

### Instance methods inherited from struct `Value`

==(other) ==, dup dup

### Instance methods inherited from class `Object`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try, unsafe_as(type : T.class) forall T unsafe_as

### Constructor methods inherited from class `Object`

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self from_json, from_yaml(string_or_io) : self from_yaml

## Constructor Detail

def self.new(&block : Int32 -> T) #

Creates a new static array and invokes the block once for each index of the array, assigning the block's value in that index.

    StaticArray(Int32, 3).new { |i| i * 2 } # => StaticArray[0, 2, 4]

def self.new(value : T) #

Creates a new static array filled with the given value.

    StaticArray(Int32, 3).new(42) # => StaticArray[42, 42, 42]

## Instance Method Detail

def ==(other : StaticArray) #

Equality. Returns `true` if each element in `self` is equal to each corresponding element in other.

    array = StaticArray(Int32, 3).new 0  # => StaticArray[0, 0, 0]
    array2 = StaticArray(Int32, 3).new 0 # => StaticArray[0, 0, 0]
    array3 = StaticArray(Int32, 3).new 1 # => StaticArray[1, 1, 1]
    array == array2                      # => true
    array == array3                      # => false

def ==(other) #

Equality with another object. Always returns `false`.

    array = StaticArray(Int32, 3).new 0 # => StaticArray[0, 0, 0]
    array == nil                        # => false

def []=(index : Int, value : T) #

Sets the given value at the given index.

Negative indices can be used to start counting from the end of the array. Raises `IndexError` if trying to set an element outside the array's range.

    array = StaticArray(Int32, 3).new { |i| i + 1 } # => StaticArray[1, 2, 3]
    array[2] = 2                                    # => 2
    array                                           # => StaticArray[1, 2, 2]
    array[4] = 4                                    # raises IndexError

def []=(value : T) #

Fills the array by substituting all elements with the given value.

    array = StaticArray(Int32, 3).new { |i| i + 1 }
    array.[]= 2 # => nil
    array       # => StaticArray[2, 2, 2]

def clone #

Returns a new `StaticArray` where each element is cloned from elements in `self`.

def map!(&block) #

Invokes the given block for each element of `self`, replacing the element with the value returned by the block. Returns `self`.

    array = StaticArray(Int32, 3).new { |i| i + 1 }
    array.map! { |x| x*x } # => StaticArray[1, 4, 9]

def map_with_index!(&block : T, Int32 -> T) #

Like `map`, but the block gets passed both the element and its index.

def pretty_print(pp) #
def reverse! #

Reverses the elements of this array in-place, then returns `self`.

    array = StaticArray(Int32, 3).new { |i| i + 1 }
    array.reverse! # => StaticArray[3, 2, 1]

def shuffle!(random = Random::DEFAULT) #

Modifies `self` by randomizing the order of elements in the array using the given random number generator. Returns `self`.

    a = StaticArray(Int32, 3).new { |i| i + 1 } # => StaticArray[1, 2, 3]
    a.shuffle!(Random.new(42))                  # => StaticArray[3, 2, 1]
    a                                           # => StaticArray[3, 2, 1]

def size #

Returns the size of `self`

    array = StaticArray(Int32, 3).new { |i| i + 1 }
    array.size # => 3

def to_s(io : IO) #

Appends a string representation of this static array to the given `IO`.

    array = StaticArray(Int32, 3).new { |i| i + 1 }
    array.to_s # => "StaticArray[1, 2, 3]"

def to_slice #

Returns a slice that points to the elements of this static array. Changes made to the returned slice also affect this static array.

    array = StaticArray(Int32, 3).new(2)
    slice = array.to_slice # => Slice[2, 2, 2]
    slice[0] = 3
    array # => StaticArray[3, 2, 2]

def to_unsafe : Pointer(T) #

Returns a pointer to this static array's data.

    ary = StaticArray(Int32, 3).new(42)
    ary.to_unsafe[0] # => 42

def unsafe_at(index : Int) #
def update(index : Int, &block) #

Yields the current element at the given index and updates the value at the given index with the block's value. Raises `IndexError` if trying to set an element outside the array's range.

    array = StaticArray(Int32, 3).new { |i| i + 1 } # => StaticArray[1, 2, 3]
    array.update(1) { |x| x * 2 }                   # => 4
    array                                           # => StaticArray[1, 4, 3]
    array.update(5) { |x| x * 2 }                   # raises IndexError

## Macro Detail

macro [](*args) #

Create a new `StaticArray` with the given args. The type of the static array will be the union of the type of the given args, and its size will be the number of elements in args.

    ary = StaticArray[1, 'a']
    ary[0]    # => 1
    ary[1]    # => 'a'
    ary.class # => StaticArray(Char | Int32, 2)

See also: `Number.static_array`.