mirror of
https://github.com/tappollo/OSCKit.git
synced 2026-03-29 01:28:05 +08:00
31 lines
582 B
Swift
31 lines
582 B
Swift
//
|
|
// OptionalThrow.swift
|
|
// ThreeSixtyCamera
|
|
//
|
|
// Created by Zhigang Fang on 4/18/17.
|
|
// Copyright © 2017 Tappollo Inc. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
infix operator !! : LogicalConjunctionPrecedence
|
|
|
|
func !!<T>(optional: Optional<T>, error: Error) throws -> T {
|
|
return try optional.someOrThrow(error)
|
|
}
|
|
|
|
extension Optional {
|
|
func someOrThrow(_ error: Error) throws -> Wrapped {
|
|
if let value = self {
|
|
return value
|
|
}
|
|
throw error
|
|
}
|
|
}
|
|
|
|
func const<T, V>(value: T) -> (V) -> T {
|
|
return { _ in
|
|
value
|
|
}
|
|
}
|