Dictionary

struct Dictionary<Key, Value> where Key : Hashable
  • Get a value for a given key and return as an object V. If the value is not of the type V throws an error.

    Throws

    ParserError if key doesn’t exists in the dictionary or it is not of the type V.

    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 object V. If the value is not of the type V throws an error.

    Throws

    ParserError if value is not of the type V.

    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, or nil if key doesn’t exists in the dictionary.

  • Get a value for a given key and return as an object U by transforming it from a type V to a type U.

    Throws

    ParserError if key doesn’t exists in the dictionary or it is not of the type V, or it couldn’t be transformed to type U.

    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 to U.

    Return Value

    The value associated with key.

  • Get a value for a given key and return as an optional object U by transforming it from a type V to a type U.

    Throws

    ParserError if value is not of the type V, or it couldn’t be transformed to type U.

    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 to U.

    Return Value

    The value associated with key.

  • Get a value for a given key and return as an optional array of object U by transforming each object of a type V to a type U.

    Throws

    ParserError if objects cannot be transformed to type U.

    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 to U.

    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.