Skip to content

Commit 73e3b0a

Browse files
committed
---
yaml --- r: 7026 b: refs/heads/master c: b02a77d h: refs/heads/master v: v3
1 parent 6344592 commit 73e3b0a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 94d40be746299ffde4893ad4a74c9fd6c1e3652f
2+
refs/heads/master: b02a77d6b471fe76e8c88ea8462a5251f7744ca3
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
iface to_str {
2+
fn to_str() -> str;
3+
}
4+
impl of to_str for int {
5+
fn to_str() -> str { int::str(self) }
6+
}
7+
impl of to_str for str {
8+
fn to_str() -> str { self }
9+
}
10+
11+
iface map<T> {
12+
fn map<U>(f: block(T) -> U) -> [U];
13+
}
14+
impl <T> of map<T> for [T] {
15+
fn map<U>(f: block(T) -> U) -> [U] {
16+
let r = [];
17+
for x in self { r += [f(x)]; }
18+
r
19+
}
20+
}
21+
22+
fn foo<U, T: map<U>>(x: T) -> [str] {
23+
x.map({|_e| "hi" })
24+
}
25+
fn bar<U: to_str, T: map<U>>(x: T) -> [str] {
26+
x.map({|_e| _e.to_str() })
27+
}
28+
29+
fn main() {
30+
assert foo([1]) == ["hi"];
31+
assert bar::<int, [int]>([4, 5]) == ["4", "5"];
32+
assert bar::<str, [str]>(["x", "y"]) == ["x", "y"];
33+
}

0 commit comments

Comments
 (0)