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
use alloc::{vec, vec::Vec};
use core::ops::Deref;

use unconst::unconst;

use crate::traits::Integral;

#[unconst]
#[derive_const(Clone, PartialEq, PartialOrd, Ord)]
#[derive(Debug, Eq)]
pub struct Seq<I: ~const Integral>(Vec<I>);

#[unconst]
impl<I: ~const Integral> Seq<I> {
    pub const fn empty() -> Self {
        Seq(Vec::new())
    }

    pub const fn new<M: ~const IntoIterator<Item = I>>(is: M) -> Self {
        Seq(is.into_iter().collect())
    }

    pub const fn one(i: I) -> Self {
        Seq(vec![i])
    }

    pub const fn mul(mut self, other: Self) -> Self {
        self.0.extend(other);
        self
    }

    pub const fn rev(self) -> Self {
        Seq(self.0.into_iter().rev().collect())
    }
}

#[unconst]
impl<I: ~const Integral> const AsRef<[I]> for Seq<I> {
    fn as_ref(&self) -> &[I] {
        &self.0
    }
}

#[unconst]
impl<I: ~const Integral> const Deref for Seq<I> {
    type Target = Vec<I>;
    fn deref(&self) -> &Vec<I> {
        &self.0
    }
}

#[unconst]
impl<I: ~const Integral> const IntoIterator for Seq<I> {
    type Item = I;
    type IntoIter = <Vec<I> as IntoIterator>::IntoIter;

    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}