-
Notifications
You must be signed in to change notification settings - Fork 45
OrderedDictionary
A simple implementation of an Ordered Dictionary based
on the existing Foundation Dictionary and Array types.
Undoubtedly not the fastest performer, but should be sufficient
for the purposes of this library.
public struct OrderedDictionary<Key, Value> where Key: Hashable The Encoding/Decoding behavior of this type differs from that
of Dictionary both in that ordering is retained and also
in that an OrderedDictionary with any Key type that
is LosslessStringConvertible or RawRepresentable
as String will encode as a hash whereas non-String
keys result in Dictionary encoding as a list of alternating
keys and values.
Collection, Decodable, Encodable, ExpressibleByDictionaryLiteral, StringRawKeyEncodable, LosslessStringKeyDecodable, StringRawKeyDecodable
public init() public init<S>(
grouping values: S,
by keyForValue: (S.Element) throws -> Key
) rethrows where Value == [S.Element], S : Sequence public init<S>(
_ keysAndValues: S,
uniquingKeysWith combine: (Value, Value) throws -> Value
) rethrows where S : Sequence, S.Element == (Key, Value) public init(dictionaryLiteral elements: (Key, Value)...) Get the keys in this dictionary in order.
public var keys: [Key] Get the values in this dictionary in order.
public var values: [Value] public var startIndex: Int public var endIndex: Int Returns whether this dictionary contains a key fulfilling the given predicate.
public func contains(where predicate: (Key) throws -> Bool) rethrows -> Bool Returns whether the dictionary contains the given key.
public func contains(key: Key) -> Bool Returns a new dictionary containing the keys of this dictionary with the values transformed by the given closure.
public func mapValues<T>(_ transform: (Value) throws -> T) rethrows -> OrderedDictionary<Key, T> - transform: A closure that transforms a value.
transformaccepts each value of the dictionary as its parameter and returns a transformed value of the same or of a different type.
A dictionary containing the keys and transformed values of this dictionary.
Returns a new dictionary containing only the key-value pairs that have
non-nil values as the result of transformation by the given closure.
public func compactMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> OrderedDictionary<Key, T> Use this method to receive a dictionary with non-optional values when your transformation produces optional values.
In this example, note the difference in the result of using mapValues
and compactMapValues with a transformation that returns an optional
Int value.
let data = ["a": "1", "b": "three", "c": "///4///"]
let m: [String: Int?] = data.mapValues { str in Int(str) }
// ["a": 1, "b": nil, "c": nil]
let c: [String: Int] = data.compactMapValues { str in Int(str) }
// ["a": 1]
- transform: A closure that transforms a value.
transformaccepts each value of the dictionary as its parameter and returns an optional transformed value of the same or of a different type.
A dictionary containing the keys and non-nil transformed values of this dictionary.
public func index(after i: Int) -> Int public func makeIterator() -> Iterator .
Types
- AnyCodable
- DereferencedContent
- DereferencedContentEncoding
- DereferencedDocument
- DereferencedDocument.Route
- DereferencedHeader
- DereferencedJSONSchema
- DereferencedJSONSchema.ArrayContext
- DereferencedJSONSchema.ObjectContext
- DereferencedOperation
- DereferencedOperation.ResponseOutcome
- DereferencedParameter
- DereferencedPathItem
- DereferencedPathItem.Endpoint
- DereferencedRequest
- DereferencedResponse
- DereferencedSchemaContext
- DereferencedSecurityRequirement
- DereferencedSecurityRequirement.ScopedScheme
- Either
- EitherDecodeNoTypesMatchedError
- EitherDecodeNoTypesMatchedError.IndividualFailure
- ErrorCategory
- ErrorCategory.KeyValue
- InconsistencyError
- JSONReference
- JSONReference.InternalReference
- JSONReference.Path
- JSONReference.PathComponent
- JSONSchema
- JSONSchema.ArrayContext
- JSONSchema.CoreContext
- JSONSchema.CoreContext.Permissions
- JSONSchema.IntegerContext
- JSONSchema.IntegerContext.Bound
- JSONSchema.NumericContext
- JSONSchema.NumericContext.Bound
- JSONSchema.ObjectContext
- JSONSchema.StringContext
- JSONSchemaResolutionError
- JSONType
- JSONTypeFormat
- JSONTypeFormat.AnyFormat
- JSONTypeFormat.ArrayFormat
- JSONTypeFormat.BooleanFormat
- JSONTypeFormat.IntegerFormat
- JSONTypeFormat.IntegerFormat.Extended
- JSONTypeFormat.NumberFormat
- JSONTypeFormat.ObjectFormat
- JSONTypeFormat.StringFormat
- JSONTypeFormat.StringFormat.Extended
- OpenAPI
- OpenAPI.CallbackURL
- OpenAPI.ComponentKey
- OpenAPI.Components
- OpenAPI.Components.ReferenceCycleError
- OpenAPI.Components.ReferenceError
- OpenAPI.Content
- OpenAPI.Content.Encoding
- OpenAPI.ContentType
- OpenAPI.Discriminator
- OpenAPI.Document
- OpenAPI.Document.Info
- OpenAPI.Document.Info.Contact
- OpenAPI.Document.Info.License
- OpenAPI.Document.Route
- OpenAPI.Document.Version
- OpenAPI.Error
- OpenAPI.Error.Decoding
- OpenAPI.Error.Decoding.Document
- OpenAPI.Error.Decoding.Document.Context
- OpenAPI.Error.Decoding.Operation
- OpenAPI.Error.Decoding.Operation.Context
- OpenAPI.Error.Decoding.Path
- OpenAPI.Error.Decoding.Path.Context
- OpenAPI.Error.Decoding.Request
- OpenAPI.Error.Decoding.Request.Context
- OpenAPI.Error.Decoding.Response
- OpenAPI.Error.Decoding.Response.Context
- OpenAPI.Example
- OpenAPI.ExternalDocumentation
- OpenAPI.Header
- OpenAPI.HttpMethod
- OpenAPI.Link
- OpenAPI.OAuthFlows
- OpenAPI.OAuthFlows.AuthorizationCode
- OpenAPI.OAuthFlows.ClientCredentials
- OpenAPI.OAuthFlows.CommonFields
- OpenAPI.OAuthFlows.Implicit
- OpenAPI.OAuthFlows.Password
- OpenAPI.Operation
- OpenAPI.Operation.ResponseOutcome
- OpenAPI.Parameter
- OpenAPI.Parameter.Context
- OpenAPI.Parameter.Context.Location
- OpenAPI.Parameter.SchemaContext
- OpenAPI.Parameter.SchemaContext.Style
- OpenAPI.Path
- OpenAPI.PathItem
- OpenAPI.PathItem.Endpoint
- OpenAPI.Request
- OpenAPI.Response
- OpenAPI.Response.StatusCode
- OpenAPI.Response.StatusCode.Range
- OpenAPI.RuntimeExpression
- OpenAPI.RuntimeExpression.Source
- OpenAPI.SecurityScheme
- OpenAPI.SecurityScheme.Location
- OpenAPI.SecurityScheme.SecurityType
- OpenAPI.SecurityScheme.SecurityType.Name
- OpenAPI.Server
- OpenAPI.Server.Variable
- OpenAPI.Tag
- OpenAPI.XML
- OrderedDictionary
- OrderedDictionary.Iterator
- ResolvedDocument
- ResolvedEndpoint
- ResolvedRoute
- URLTemplate
- URLTemplate.Component
- Validation
- ValidationContext
- ValidationError
- ValidationErrorCollection
- Validator
- Validator.CodingKey
Protocols
Global Functions
Extensions
- Array
- Bool
- Dictionary
- Double
- Float
- Int
- Int32
- Int64
- OpenAPI.Callbacks
- OpenAPI.Content.Encoding
- OpenAPI.Document.Info
- OpenAPI.Document.Info.Contact
- OpenAPI.Document.Info.License
- OpenAPI.Error.Decoding
- OpenAPI.Error.Decoding.Document
- OpenAPI.Error.Decoding.Operation
- OpenAPI.Error.Decoding.Path
- OpenAPI.Error.Decoding.Request
- OpenAPI.Error.Decoding.Response
- OpenAPI.OAuthFlows.AuthorizationCode
- OpenAPI.OAuthFlows.ClientCredentials
- OpenAPI.OAuthFlows.CommonFields
- OpenAPI.OAuthFlows.Implicit
- OpenAPI.OAuthFlows.Password
- OpenAPI.Parameter.Context
- OpenAPI.Parameter.SchemaContext
- OpenAPI.Response.StatusCode
- OpenAPI.Server.Variable
- Optional
- String
- URL
- UUID