Slide 12
Slide 12 text
1. 型やデータの責務がより明確になった
2. コーディング時のコードが読みやすくなった
良かったこと
12
TypeScript
● パターンマッチがない
● 所有権がない
Rust
● パターンマッチがある
● 所有権がある
impl Foo {
fn 手数料(&self): Option {
match (self.手数料1, self.手数料2, self.手数料3) {
(Some(手数料1), _, _) => Some(手数料1),
(None, Some(手数料2), _) => Some(手数料2),
(None, None, 手数料3) => 手数料3,
}
}
}
function 手数料(foo: Foo): number | null {
if (foo.手数料1 !== null) return foo.手数料1;
if (foo.手数料2 !== null) return foo.手数料2;
return foo.手数料3;
}