// Argo
struct User {
let id: Int
let name: String
let email: String?
let role: Role
let companyName: String
let friends: [User]
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val a: Int = 999 | |
val b: Int? = a | |
val c: Int? = a | |
println(b === c) // false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CountableRange { | |
public func contains(_ range: CountableRange<Bound>) -> Bool { | |
return lowerBound <= range.lowerBound && range.upperBound <= upperBound | |
} | |
public func contains(_ range: CountableClosedRange<Bound>) -> Bool { | |
return lowerBound <= range.lowerBound && range.upperBound < upperBound | |
} | |
public func contains(_ range: Range<Bound>) -> Bool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Animal | |
class Cat: Animal() | |
class Box<out Value> ( // `out` for covariance | |
val value: Value | |
) | |
fun main(args: Array<String>) { | |
val catBox: Box<Cat> = Box(Cat()) | |
val animalBox: Box<Animal> = catBox // OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal {} | |
class Cat: Animal {} | |
let cats: Array<Cat> = [Cat()] | |
let animals: Array<Animal> = cats // OK | |
let cat: Optional<Cat> = .some(Cat()) | |
let animal: Optional<Animal> = cat // OK | |
struct Box<Value> { |
eachPair
without AnySequence
extension Sequence where Self.SubSequence: Sequence {
func eachPair() -> Zip2Sequence<Self, Self.SubSequence> {
return zip(self, self.dropFirst())
}
}
(1...10).eachPair().forEach { print($0) }
This is a catalog of translations by SwiftScript, a transpiler from Swift to JavaScript, for a hackathon. It supports only a subset of Swift and has some incompatibilities.
SwiftScript tries to translate Swift codes to JS codes using builtin JS APIs. However some needs a supporting library to simulate behaviors of Swift. A typical example is ?.
.
If
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericReturnType { | |
public static void main(String[] args) { | |
// 引数の型は `Object` なので戻り値から型パラメータが推論される | |
Integer n = id(42); | |
String s = id("xyz"); | |
System.out.println(n); | |
System.out.println(s); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func foo() -> Int { return 2 } | |
func foo() -> Float { return 3.0 } | |
let a: Int = foo() | |
let b: Float = foo() | |
print(a) // 2 | |
print(b) // 3.0 |