blob: f4a804e7490c3e34e98b85275b13a49751f7af44 (
plain)
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
|
//-----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//-----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
namespace Chalice
{
public class ImmutableList<E>
{
private List<E> list;
public ImmutableList() {
list = new List<E>();
}
public ImmutableList(IEnumerable<E> elems)
{
list = new List<E>(elems);
}
public ImmutableList<E> Append(ImmutableList<E> other)
{
var res = new ImmutableList<E>();
res.list.AddRange(list);
res.list.AddRange(other.list);
return res;
}
public E At(int index)
{
return list[index];
}
public ImmutableList<E> Take(int howMany)
{
var res = new ImmutableList<E>(this.list.Take(howMany));
return res;
}
public ImmutableList<E> Drop(int howMany)
{
var res = new ImmutableList<E>(this.list.Skip(howMany));
return res;
}
public int Length
{
get
{
return list.Count;
}
}
public static ImmutableList<int> Range(int min, int max)
{
ImmutableList<int> l = new ImmutableList<int>();
for (int i = min; i < max; i++)
{
l.list.Add(i);
}
return l;
}
}
public class ChalicePrint {
public void Int(int x) {
System.Console.WriteLine(x);
}
public void Bool(bool x) {
System.Console.WriteLine(x);
}
}
}
|