mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
This sanitizes the semantics of _Node.Builder, removing
the (unneccessary) need to pass around hash paths.
It also slightly refactors removal operations, but stops short of
implementing node shrinking.
# Conflicts:
# Sources/PersistentCollections/Node/_Node+Builder.swift
# Sources/PersistentCollections/Node/_Node+Initializers.swift
# Sources/PersistentCollections/Node/_Node+Structural intersection.swift
# Sources/PersistentCollections/Node/_Node+Structural subtracting.swift
# Sources/PersistentCollections/Node/_Node+Subtree Modify.swift
# Sources/PersistentCollections/Node/_Node+Subtree Removals.swift
# Sources/PersistentCollections/PersistentDictionary/PersistentDictionary+Initializers.swift
# Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra Initializers.swift
# Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra intersection.swift
# Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra subtracting.swift
(cherry picked from commit c73a8caad1)
29 lines
1002 B
Swift
29 lines
1002 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2022 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension PersistentDictionary {
|
|
@inlinable
|
|
public func mapValues<T>(
|
|
_ transform: (Value) throws -> T
|
|
) rethrows -> PersistentDictionary<Key, T> {
|
|
let transformed = try _root.mapValues { try transform($0.value) }
|
|
return PersistentDictionary<Key, T>(_new: transformed)
|
|
}
|
|
|
|
@inlinable
|
|
public func compactMapValues<T>(
|
|
_ transform: (Value) throws -> T?
|
|
) rethrows -> PersistentDictionary<Key, T> {
|
|
let result = try _root.compactMapValues(.top, transform)
|
|
return PersistentDictionary<Key, T>(_new: result.finalize(.top))
|
|
}
|
|
}
|