Last active
September 2, 2017 03:51
-
-
Save davidkellis/f90febaec142b7acad39a0621ea45a40 to your computer and use it in GitHub Desktop.
interface examples that need to play nice together
This file contains 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 A for M A { | |
fn map(m: M A, convert: A -> B) -> M B | |
} | |
impl Mappable A for Array A { | |
fn map(a: Array A, convert: A -> B) -> Array B | |
} | |
impl Mappable T for Iterator T { | |
fn map(a: Iterator T, convert: T -> B) -> Array B | |
} | |
KeyMapper = impl Mappable K for Map K V { | |
fn map(m: Map K V, convert: K -> K2) -> Map K2 V { ... } | |
} | |
ValueMapper = impl Mappable V for Map K V { | |
fn map(m: Map K V, convert: V -> W) -> Map K W { ... } | |
} | |
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