session-ios/SessionUtilitiesKit/General/General.swift

6 lines
238 B
Swift

/// Returns `f(x!)` if `x != nil`, or `nil` otherwise.
public func given<T, U>(_ x: T?, _ f: (T) throws -> U) rethrows -> U? { return try x.map(f) }
public func with<T, U>(_ x: T, _ f: (T) throws -> U) rethrows -> U { return try f(x) }