Dictionary
struct Dictionary<Key, Value> where Key : Hashable
-
Get a value for a given
key
and return as an objectV
. If the value is not of the typeV
throws an error.Declaration
Swift
public func fetch<V>(_ key: Key) throws -> V
Parameters
key
The key to find in the dictionary.
Return Value
The value associated with
key
. -
Get a value for a given
key
and return as an optional objectV
. If the value is not of the typeV
throws an error.Declaration
Swift
public func fetchOptional<V>(_ key: Key) throws -> V?
Parameters
key
The key to find in the dictionary.
Return Value
The value associated with
key
, ornil
if key doesn’t exists in the dictionary. -
Get a value for a given
key
and return as an objectU
by transforming it from a typeV
to a typeU
.Throws
ParserError
ifkey
doesn’t exists in the dictionary or it is not of the typeV
, or it couldn’t be transformed to typeU
.Declaration
Swift
public func fetch<V, U>(_ key: Key, transformation: (V) throws -> U?) throws -> U
Parameters
key
The key to find in the dictionary.
transformation
Transformation closure. Transorms from type
V
toU
.Return Value
The value associated with
key
. -
Get a value for a given
key
and return as an optional objectU
by transforming it from a typeV
to a typeU
.Declaration
Swift
public func fetchOptional<V, U>(_ key: Key, transformation: (V) throws -> U?) throws -> U?
Parameters
key
The key to find in the dictionary.
transformation
Transformation closure. Transorms from type
V
toU
.Return Value
The value associated with
key
. -
Get a value for a given
key
and return as an optional array of objectU
by transforming each object of a typeV
to a typeU
.Declaration
Swift
public func fetchOptionalArray<V, U>(_ key: Key, transformation: (V) throws -> U?) throws -> [U]?
Parameters
key
The key to find in the dictionary.
transformation
Transformation closure. Transorms from type
V
toU
.Return Value
An optional array of values associated with
key
. -
Return first pair (key and value) from dictionary.
Throws
ParserError
if dictionary is empty.Declaration
Swift
public func fetchFirst() throws -> (key: Key, value: Value)
Return Value
First pair (key and value) from dictionary.
-
Return first pair (key and value) from dictionary and transform it to type
T
.Throws
ParserError
if dictionary is empty.Declaration
Swift
public func fetchFirst<T>(transformation: (Key, Value) throws -> T) throws -> T
Parameters
transformation
Transformation closure. Transorms key and value to the type
T
.Return Value
First pair (key and value) transformed to type
T
.