import Foundation

extension Optional {
    
    func map<T>(_ transform: (Wrapped) throws -> T) rethrows -> T? {
        guard let self else {
            return nil
        }
        return try transform(self)
    }

    func map<T>(_ transform: (Wrapped) throws -> T?) rethrows -> T? {
        guard let self else {
            return nil
        }
        return try transform(self)
    }
}
