Created
September 2, 2017 03:58
-
-
Save davidkellis/a9797576db519fdeeca23815c39940a7 to your computer and use it in GitHub Desktop.
interfaces extreme 2
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
interface Enumerable T for E { | |
fn each(E, T -> Unit) -> Unit | |
} | |
impl Enumerable T for Array T { | |
fn each(array: Array T, f: T -> Unit) -> Unit { ... } | |
} | |
impl Enumerable T for I : Iterator T { | |
fn each(it: I, visit: T -> Unit) = ... | |
} | |
impl Enumerable T for Iterator T { | |
fn each(it: Iterator T, visit: T -> Unit) = ... | |
} | |
KeyIterator = impl Enumerable K for Map K V { | |
fn each(m: Map K V, visit: K -> Unit) -> Unit { ... } | |
} | |
ValueIterator = impl Enumerable V for Map K V { | |
fn each(m: Map K V, visit: V -> Unit) -> Unit { ... } | |
} | |
impl Enumerable (K,V) for Map K V | |
fn each(map: Map K V, f: ( (K,V) ) -> Unit) -> Unit { ... } | |
} | |
interface Iterator T for I { | |
fn has_next?(I) -> Bool | |
fn next(I) -> Option T | |
} | |
interface Mappable Out for In { | |
fn map[A,B](m: In, convert: A -> B) -> Out // A and B must be consistent with In and Out | |
} | |
impl Mappable (Array B) for Array A { | |
fn map(a: Array A, convert: A -> B) -> Array B | |
} | |
impl Mappable (Iterator B) for Iterator A { | |
fn map(a: Iterator A, convert: A -> B) -> Iterator B | |
} | |
KeyMapper = impl Mappable (Map K2 V) for Map K V { | |
fn map(m: Map K V, convert: K -> K2) -> Map K2 V { ... } | |
} | |
ValueMapper = impl Mappable (Map K V2) for Map K V { | |
fn map(m: Map K V, convert: V -> V2) -> Map K V2 { ... } | |
} | |
iterators = Array[Iterator Int](Array(1,2,3), List(4,5,6), Range(10, 20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment