1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#![cfg_attr(feature="nightly", feature(unsize, fn_traits, unboxed_closures))]

#[cfg(feature = "par_iter")]
extern crate rayon;

#[cfg(feature = "shred")]
extern crate shred;

/// Convenient way to define heterogenous `List`
#[macro_export]
macro_rules! hlist {
    () => {
        List::new()
    };
    ($head:expr $(, $tail:expr)*) => {
        hlist![$($tail),*].push($head)
    };
}

/// Convenient way to define heterogenous `Queue`
#[macro_export]
macro_rules! hqueue {
    ($($values:expr),*) => {
        Queue::new()$(.push($values))*
    };
}

/// Convenient way to define heterogenous `Queue`
#[macro_export]
macro_rules! HQueue {
    () => {
        Queue<()>
    };
    ($($types:path),*, $last:path) => {
        Queue<(HQueue![$($types),*], $last)>
    };
}

/// This macro can be used to define lambdas with syntax similar to rust's lambdas
/// Arguments are bounded by traits
/// Mainly to use with `Functor` and `Foldable`
#[cfg(not(feature="nightly"))]
#[macro_export]
macro_rules! lambda {
    {let $n:ident = |$($an:ident $(: $at:path)*),+| -> $o:ty { $($s:stmt);* }} => {

        #[derive(Clone, Copy)]
        #[allow(non_camel_case_types)]
        pub struct $n;

        #[allow(non_camel_case_types,unused_mut)]
        impl<$($an: $($at)*,)+> $crate::HetFnOnce<($($an,)*)> for $n {
            type Output = $o;
            fn call_once(self, ($(mut $an,)*): ($($an,)*)) -> $o {
                Self::call(&self, ($($an,)*))
            }
        }

        #[allow(non_camel_case_types,unused_mut)]
        impl<$($an: $($at)*,)*> $crate::HetFnMut<($($an,)*)> for $n {
            fn call_mut(&mut self, ($(mut $an,)*): ($($an,)*)) -> $o {
                Self::call(&self, ($($an,)*))
            }
        }

        #[allow(non_camel_case_types,unused_mut)]
        impl<$($an: $($at)*,)*> $crate::HetFn<($($an,)*)> for $n {
            fn call(&self, ($(mut $an,)*): ($($an,)*)) -> $o {
                $($s);*
            }
        }
    };

    {let $n:ident$(<$($p:ident $(: $pb:path)*),+>)*($($c:ident: $ct:ty)+) = |$($an:ident $(: $at:path)*),+| -> $o:ty { $($s:stmt);* }} => {

        #[derive(Clone)]
        #[allow(non_camel_case_types)]
        pub struct $n<'a, $($($p: 'a),+)*>(::std::marker::PhantomData<&'a ()>, $($ct),+);

        impl<'a, $($($p),+)*> $n<'a, $($($p),+)*>
            where $($($p: 'a $( + $pb,)*)+)*
        {
            pub fn new($($c: $ct)+) -> Self {
                $n(::std::marker::PhantomData, $($c),+)
            }
        }

        #[allow(non_camel_case_types,unused_mut)]
        impl<'a, $($an,)+ $($($p,)+)*> $crate::HetFnOnce<($($an,)*)> for $n<'a, $($($p),+)*>
            where $($($an: $at,)*)+
                  $($($p: 'a $( + $pb,)*)+)*
        {
            type Output = $o;
            fn call_once(self, ($(mut $an,)*): ($($an,)*)) -> $o {
                $crate::HetFn::call(&self, ($($an,)*))
            }
        }

        #[allow(non_camel_case_types,unused_mut)]
        impl<'a, $($an,)+ $($($p,)+)*> $crate::HetFnMut<($($an,)*)> for $n<'a, $($($p),+)*>
            where $($($an: $at,)*)+
                  $($($p: 'a $( + $pb,)*)+)*
        {
            fn call_mut(&mut self, ($(mut $an,)*): ($($an,)*)) -> $o {
                $crate::HetFn::call(self, ($($an,)*))
            }
        }

        #[allow(non_camel_case_types,unused_mut)]
        impl<'a, $($an,)+ $($($p,)+)*> $crate::HetFn<($($an,)*)> for $n<'a, $($($p),+)*>
            where $($($an: $at,)*)+
                  $($($p: 'a $( + $pb,)*)+)*
        {
            fn call(&self, ($(mut $an,)*): ($($an,)*)) -> $o {
                let $n(_, $(ref $c,)+) = *self;
                $($s);*
            }
        }
    };
}


mod by_ref;

#[cfg(not(feature="nightly"))]
mod f;

mod fold;
mod functor;
mod len;
mod list;
mod num;
mod try;
mod queue;
mod zip;

#[cfg(feature = "par_iter")]
mod par_iter;

#[cfg(feature = "shred")]
mod system_data;

#[cfg(test)]
mod tests;

#[cfg(feature="nightly")]
mod unsize_iter;

pub use by_ref::ByRef;
#[cfg(not(feature="nightly"))]
pub use f::{HetFnOnce, HetFnMut, HetFn};
pub use fold::Foldable;
pub use functor::Functor;
pub use len::Length;
pub use list::{IntoList, List};
pub use num::{Num, P, S, Z};
pub use try::Try;
pub use queue::{IntoQueue, Queue};
pub use zip::Zip;

#[cfg(feature="nightly")]
pub use unsize_iter::{IntoRefIter, UnsizeRefIter, UnsizeRefIterator};


pub mod prelude;