test
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
import SwiftUI | |
struct ContentView: View { | |
@StateObject private var state: ContentViewState = .init() | |
var body: some View { | |
ZStack { | |
VStack { | |
Text(state.count.description) | |
Button("Count Up") { |
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 readInt3(line: Int = #line, file: String = #file) -> (Int, Int, Int) { | |
guard let string = readLine() else { | |
preconditionFailure("No input (at line \(line) in \(file))") | |
} | |
let values: [Int] = string.split(separator: " ").map { part in | |
guard let value = Int(part) else { | |
preconditionFailure("Illegal input value: \(string) (at line \(line) in \(file))") | |
} | |
return value | |
} |
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 pow<Integer>(_ a: Integer, _ b: Integer, modulus: Integer?) -> Integer where Integer: BinaryInteger { | |
var result: Integer = 1 | |
var a = a | |
var b = b | |
if let modulus = modulus { | |
while true { | |
if b & 0x1 != 0 { | |
result = (result * a) % modulus | |
} | |
b >>= 1 |
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
// わざわざ async let を使って代入を挟まなくても | |
// 非同期処理を↓のようにして並行に実行できるようにするのは | |
// | |
// await (foo() + bar()) // 並行 | |
// (await foo()) + (await bar()) // 直列 | |
// | |
// try との整合性の関係で難しそう。 | |
// | |
// try の仕様が、↓の (A) では "foo" と "bar" が、 | |
// (B) では "foo" のみが表示されるようになっていれば |
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
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
ScrollView { | |
MyView() | |
Text("Hello") | |
} | |
} | |
} |
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
import SwiftUI | |
extension Binding: Identifiable where Value: Identifiable { | |
public var id: Value.ID { | |
wrappedValue.id | |
} | |
} | |
extension Binding: Sequence where Value: MutableCollection, Value: RandomAccessCollection, Value.Element: Identifiable { | |
public typealias Element = Binding<Value.Element> |
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
import Foundation | |
func measure(_ body: () -> Void) { | |
let start = Date.timeIntervalSinceReferenceDate | |
for _ in 0 ..< 10 { | |
body() | |
} | |
let end = Date.timeIntervalSinceReferenceDate | |
print((end - start) / 10) | |
} |
キャパシティが増加したタイミングでバッファが作り直されている気がします
これはそうだと思います。その上で、↓のような疑問を持っています。
まず、 ArraySlice
の挙動として、 popFirst
した場合 startIndex
がインクリメントされるだけで、各要素のインデックスは変化しません。
var a: ArraySlice<Int> = [2, 3, 5]
_ = a.popFirst()
print(a[1]) // 3
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
let xzs = [ | |
(3333, 8650), | |
(3333, 8634), | |
(3342, 8634), | |
(3342, 8633), | |
(3352, 8633), | |
(3352, 8634), | |
(3360, 8634), | |
(3360, 8638), | |
(3361, 8638), |