Avatar
できた。
2:30 AM
struct CastError: Error {} func cast<T, U>(to type: U.Type) -> (T) throws -> U { return { value in guard let value = value as? U else { throw CastError() } return value } } infix operator => : SwifletPrecedence precedencegroup SwifletPrecedence { higherThan: AssignmentPrecedence associativity: left } public func =><T, U>(lhs: T, rhs: (T) throws -> U) rethrows -> U { return try rhs(lhs) } let a: Int = 42 let b: Any = a print(try! b => cast(to: Int.self)) // 42 (edited)
2:31 AM
関係ないけど、なんで higherThan って higherthan じゃないんだろう?🤔