session-ios/SessionUtilitiesKit/General/General.swift

12 lines
496 B
Swift
Raw Normal View History

2020-12-06 23:29:46 +01:00
2021-05-28 01:47:05 +02:00
/// Does nothing, but is never inlined and thus evaluating its argument will never be optimized away.
///
/// Useful for forcing the instantiation of lazy properties like globals.
@inline(never)
public func touch<Value>(_ value: Value) { /* Do nothing */ }
2020-12-06 23:29:46 +01:00
/// 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) }
2021-01-29 01:46:32 +01:00
public func with<T, U>(_ x: T, _ f: (T) throws -> U) rethrows -> U { return try f(x) }