1 module viva.types.collection;
2 
3 import viva.collections;
4 import viva.types..string;
5 
6 /++
7  +
8  +/
9 void forEach(T)(ref T[] arr, void delegate(ref T t) callback)
10 {
11     foreach (ref e; arr)
12     {
13         callback(e);
14     }
15 }
16 
17 /++
18  +
19  +/
20 void forEach(T)(ref T[] arr, void delegate(T t) callback)
21 {
22     foreach (e; arr)
23     {
24         callback(e);
25     }
26 }
27 
28 /++
29  +
30  +/
31 void forEach(ref HashTable table, void delegate(ref EntryValue value) callback)
32 {
33     foreach (ref entryValue; table.getAll())
34     {
35         callback(entryValue);
36     }
37 }
38 
39 /++
40  +
41  +/
42 void forEach(ref HashTable table, void delegate(EntryValue value) callback)
43 {
44     foreach (entryValue; table.getAll())
45     {
46         callback(entryValue);
47     }
48 }
49 
50 /++
51  +
52  +/
53 void forEach(T)(ref Cache!T cache, void delegate(ref EntryValue value) callback)
54 {
55     foreach (ref entryValue; cache.getAll())
56     {
57         callback(entryValue);
58     }
59 }
60 
61 /++
62  +
63  +/
64 void forEach(T)(ref Cache!T cache, void delegate(EntryValue value) callback)
65 {
66     foreach (entryValue; cache.getAll())
67     {
68         callback(entryValue);
69     }
70 }
71 
72 /++
73  +
74  +/
75 string join(T)(ref T[] arr, string joiner)
76 {
77     import std.conv : to;
78 
79     string res = "";
80 
81     foreach (elem; arr)
82     {
83         res.append(elem.to!string);
84         res.append(joiner);
85     }
86     
87     res = res[0..$ - joiner.length];
88 
89     return res;
90 }