Created
April 4, 2014 20:07
-
-
Save Ygg01/9982209 to your computer and use it in GitHub Desktop.
An attempt at Decart multiplicate
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
use std::vec::Vec; | |
struct MultiplyMap<'a, T> { | |
vec: Vec<T>, | |
oper: 'a |T,T|-> T | |
} | |
impl<'a> MultiplyMap<'a, ~str>{ | |
pub fn new(data: Vec<~str>) -> MultiplyMap<'a, ~str> { | |
MultiplyMap{ | |
vec: data, | |
oper: |a: ~str, b: ~str| -> ~str { | |
let mut result = ~""; | |
result.push_str(a); | |
result.push_str(b); | |
result | |
} | |
} | |
} | |
} | |
trait Multiplier<'a, T> { | |
fn multiply_map(&'a self, MultiplyMap<'a,T>) | |
-> MultiplyMap<'a, T>; | |
} | |
impl <'a> Multiplier<'a, ~str> for MultiplyMap<'a, ~str> { | |
fn multiply_map(&self, oth: MultiplyMap<'a,~str>) | |
-> MultiplyMap<'a,~str> { | |
let mut vec = Vec::new(); | |
for i in self.vec.iter() { | |
for j in oth.vec.iter() { | |
let mut s = ~""; | |
s.push_str(*i); | |
s.push_str(*j); | |
vec.push(s); | |
} | |
} | |
MultiplyMap::new(vec) | |
} | |
} | |
fn main() { | |
let mult = (MultiplyMap::new(vec!(~"A",~"E"))) | |
.multiply_map(MultiplyMap::new(vec!(~"F",~"H"))) | |
.multiply_map(MultiplyMap::new(vec!(~"2",~"4")));; | |
println!("Vec : {:}", mult.vec); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment