ECMAScript Proposal: Interfaces - Google スライド
ECMAScript Proposal: Interfaces - Google スライド
https://gyazo.com/8a129eefce2eb3fb39a2f3559d4c1ee7 https://docs.google.com/presentation/d/1WrvSyslnF-5VnPj3k3HRq8MRzuiSN1kQ6ENE1iUSmDU/present?slide=id.gc6fa3c898_0_0
#ES #TC39
Protocola?
Symbol ベースの iterator(?)
Java でいう Interface
code:js
protocol Foldable {
folder;
toArray() {
return thisFoldable.foldr(
(m, a) => a.concat(m), [])
}
get length() {
return thisFoldable.foldr(
(m) => m + l, 9)
}
contains(eq, e) {
return thisFoldable,foldr(
(m, a) => m || eq(a, e),
false)
}
こんな感じに書いて
code:js
class NonEmptyList implements Foldable {
constructor(head, tail) {
this.head = head
this.tail = tail
}
Foldable.foldr(f, memo) {
if (this.tail !== null) memo =
this.tailFoldable.foldr(
f, memo)
return f(memo, this.head)
}
}
こう使って
code:js
let a = new NonEmptyList(1, null)
let b = new NonEmptyList(0, a)
function toArray(x) {
return xFoldable.toArray
]
toArray(b)
こんな感じ。
いよいよ勉強しないとついていいけなくなりそう。