Skip to content

Instantly share code, notes, and snippets.

@davidsteppenbeck
davidsteppenbeck / Optional+Utilities.swift
Last active July 27, 2021 07:08
An infix operator for collections that returns the wrapped value of the optional only if the collection is not empty.
import Foundation
infix operator ???
extension Optional where Wrapped: Collection {
/// Performs a nil-coalescing operation, returning the wrapped value of an `Optional` instance
/// only if the wrapped value is not empty, otherwise returns a default value.
///
/// - Parameters: