@@ -52,6 +52,67 @@ pub trait Signal {
52
52
/// ```
53
53
fn next ( & mut self ) -> Self :: Frame ;
54
54
55
+ /// A signal that maps one set of frames to another
56
+ ///
57
+ /// # Example
58
+ ///
59
+ /// ```rust
60
+ /// extern crate sample;
61
+ ///
62
+ /// use sample::{signal, Signal};
63
+ ///
64
+ /// fn main() {
65
+ /// let frames = signal::gen(|| [0.5]);
66
+ /// let mut mapper = frames.map(|f| [f[0], 0.25]);
67
+ /// assert_eq!(mapper.next(), [0.5, 0.25]);
68
+ /// assert_eq!(mapper.next(), [0.5, 0.25]);
69
+ /// assert_eq!(mapper.next(), [0.5, 0.25]);
70
+ /// }
71
+ /// ```
72
+ fn map < M , F > ( self , map : M ) -> Map < Self , M , F >
73
+ where Self : Sized ,
74
+ M : FnMut ( Self :: Frame ) -> F ,
75
+ F : Frame ,
76
+ {
77
+ Map {
78
+ signal : self ,
79
+ map : map,
80
+ frame : core:: marker:: PhantomData ,
81
+ }
82
+ }
83
+
84
+ /// A signal that maps one set of frames to another
85
+ ///
86
+ /// # Example
87
+ ///
88
+ /// ```rust
89
+ /// extern crate sample;
90
+ ///
91
+ /// use sample::{signal, Signal};
92
+ ///
93
+ /// fn main() {
94
+ /// let frames = signal::gen(|| [0.5]);
95
+ /// let more_frames = signal::gen(|| [0.25]);
96
+ /// let mut mapper = frames.zip_map(more_frames, |f, o| [f[0], o[0]]);
97
+ /// assert_eq!(mapper.next(), [0.5, 0.25]);
98
+ /// assert_eq!(mapper.next(), [0.5, 0.25]);
99
+ /// assert_eq!(mapper.next(), [0.5, 0.25]);
100
+ /// }
101
+ /// ```
102
+ fn zip_map < O , M , F > ( self , other : O , map : M ) -> ZipMap < Self , O , M , F >
103
+ where Self : Sized ,
104
+ M : FnMut ( Self :: Frame , O :: Frame ) -> F ,
105
+ O : Signal ,
106
+ F : Frame ,
107
+ {
108
+ ZipMap {
109
+ this : self ,
110
+ map : map,
111
+ other : other,
112
+ frame : core:: marker:: PhantomData ,
113
+ }
114
+ }
115
+
55
116
/// Provides an iterator that yields the sum of the frames yielded by both `other` and `self`
56
117
/// in lock-step.
57
118
///
@@ -558,18 +619,18 @@ pub struct GenMut<G, F> {
558
619
559
620
/// A signal that maps from one signal to another
560
621
#[ derive( Clone ) ]
561
- pub struct Map < M , S , F > {
562
- map : M ,
622
+ pub struct Map < S , M , F > {
563
623
signal : S ,
564
- frames : core:: marker:: PhantomData < F > ,
624
+ map : M ,
625
+ frame : core:: marker:: PhantomData < F > ,
565
626
}
566
627
567
628
/// A signal that iterates two signals in parallel and combines them with a function
568
629
#[ derive( Clone ) ]
569
- pub struct ZipMap < M , S , O , F > {
570
- map : M ,
630
+ pub struct ZipMap < S , O , M , F > {
571
631
this : S ,
572
632
other : O ,
633
+ map : M ,
573
634
frame : core:: marker:: PhantomData < F >
574
635
}
575
636
@@ -882,68 +943,6 @@ pub fn gen_mut<G, F>(gen_mut: G) -> GenMut<G, F>
882
943
}
883
944
884
945
885
- /// A signal that maps one set of frames to another
886
- ///
887
- /// # Example
888
- ///
889
- /// ```rust
890
- /// extern crate sample;
891
- ///
892
- /// use sample::{signal, Signal};
893
- ///
894
- /// fn main() {
895
- /// let frames = signal::gen(|| [0.5]);
896
- /// let mut mapper = signal::map(frames, |f| [f[0], 0.25]);
897
- /// assert_eq!(mapper.next(), [0.5, 0.25]);
898
- /// assert_eq!(mapper.next(), [0.5, 0.25]);
899
- /// assert_eq!(mapper.next(), [0.5, 0.25]);
900
- /// }
901
- /// ```
902
- pub fn map < M , S , F > ( signal : S , map : M ) -> Map < M , S , F >
903
- where M : FnMut ( S :: Frame ) -> F ,
904
- S : Signal ,
905
- F : Frame ,
906
- {
907
- Map {
908
- map : map,
909
- signal : signal,
910
- frames : core:: marker:: PhantomData ,
911
- }
912
- }
913
-
914
-
915
- /// A signal that maps one set of frames to another
916
- ///
917
- /// # Example
918
- ///
919
- /// ```rust
920
- /// extern crate sample;
921
- ///
922
- /// use sample::{signal, Signal};
923
- ///
924
- /// fn main() {
925
- /// let frames = signal::gen(|| [0.5]);
926
- /// let more_frames = signal::gen(|| [0.25]);
927
- /// let mut mapper = signal::zip_map(frames, more_frames, |f, o| [f[0], o[0]]);
928
- /// assert_eq!(mapper.next(), [0.5, 0.25]);
929
- /// assert_eq!(mapper.next(), [0.5, 0.25]);
930
- /// assert_eq!(mapper.next(), [0.5, 0.25]);
931
- /// }
932
- /// ```
933
- pub fn zip_map < M , S , O , F > ( this : S , other : O , map : M ) -> ZipMap < M , S , O , F >
934
- where M : FnMut ( S :: Frame , O :: Frame ) -> F ,
935
- S : Signal ,
936
- O : Signal ,
937
- F : Frame ,
938
- {
939
- ZipMap {
940
- map : map,
941
- this : this,
942
- other : other,
943
- frame : core:: marker:: PhantomData ,
944
- }
945
- }
946
-
947
946
948
947
/// Create a new `Signal` from the given `Frame`-yielding `Iterator`.
949
948
///
@@ -1239,9 +1238,9 @@ impl<G, F> Signal for GenMut<G, F>
1239
1238
}
1240
1239
1241
1240
1242
- impl < M , S , F > Signal for Map < M , S , F >
1243
- where M : FnMut ( S :: Frame ) -> F ,
1244
- S : Signal ,
1241
+ impl < S , M , F > Signal for Map < S , M , F >
1242
+ where S : Signal ,
1243
+ M : FnMut ( S :: Frame ) -> F ,
1245
1244
F : Frame ,
1246
1245
{
1247
1246
type Frame = F ;
@@ -1252,10 +1251,10 @@ impl<M, S, F> Signal for Map<M, S, F>
1252
1251
}
1253
1252
1254
1253
1255
- impl < M , S , O , F > Signal for ZipMap < M , S , O , F >
1256
- where M : FnMut ( S :: Frame , O :: Frame ) -> F ,
1257
- S : Signal ,
1254
+ impl < S , O , M , F > Signal for ZipMap < S , O , M , F >
1255
+ where S : Signal ,
1258
1256
O : Signal ,
1257
+ M : FnMut ( S :: Frame , O :: Frame ) -> F ,
1259
1258
F : Frame ,
1260
1259
{
1261
1260
type Frame = F ;
0 commit comments