A Swift package that provides a collection of useful data structures and extensions for working with collections in iOS, macOS, and tvOS applications.
CollectionKit extends Swift's collection types with additional functionality and provides specialized data structures for common programming needs. It includes efficient implementations of sets, queues, stacks, and more, along with convenient extensions for sequence and collection operations.
A compact set of bits backed by a byte array, perfect for efficient boolean flag storage.
var bitSet = BitSet(bitsToSet: [0, 2, 5])
bitSet.setBit(at: 7)
print(bitSet.isBitSet(at: 2)) // true
Maintains uniqueness of elements while preserving insertion order.
var orderedSet = OrderedSet<String>()
orderedSet.append("first")
orderedSet.append("second")
orderedSet.append("first") // Won't be added again
print(orderedSet.array) // ["first", "second"]
A binary heap-based priority queue with customizable comparison.
var queue = PriorityQueue<Int>(>)
queue.add([7, 5, 99, 17])
print(queue.removeFirst()) // 99 (highest priority)
Standard FIFO queue and LIFO stack implementations.
var queue = Queue<String>()
queue.enqueue("first")
queue.enqueue("second")
print(queue.dequeue()) // "first"
var stack = Stack<Int>()
stack.push(1)
stack.push(2)
print(stack.pop()) // 2
A stack that can capture and restore snapshots of its state.
Spatial data structure for efficient 2D point storage and querying.
Result builder for constructing arrays with a declarative syntax.
CollectionKit provides numerous extensions to make working with collections more convenient:
first(where:equals:)
- Find elements by key path equalitylast(where:equals:)
- Find last element by key path equalitycountWhere(_:)
- Count elements matching a conditioncontains(where:equals:)
- Check existence by key path equalitysum()
- Sum numeric sequencesunique()
- Remove duplicatestakeWhile(_:)
- Take elements while condition is trueskipWhile(_:)
- Skip elements while condition is true
chunks(of:)
- Split into chunks of specified sizeaverage()
- Calculate average of numeric collectionssafeIndex(_:)
- Safe index accessindex(of:where:equals:)
- Find index by key path equality
removeFirst(where:)
- Remove first matching elementtransformFirst(where:_:)
- Transform first matching elementsplittingOffFirst(where:)
- Split array at first match
CollectionKit is available under the BSD Zero Clause License. See the LICENSE file for more information.