add sources

This commit is contained in:
Alexander Zhirov 2023-02-26 01:19:12 +03:00
parent fcd25eea52
commit 7ce631a648
21 changed files with 548 additions and 2 deletions

View file

@ -0,0 +1,21 @@
import std.stdio;
@property bool empty(T)(T[] a) { return a.length == 0; }
@property ref T front(T)(T[] a) { return a[0]; }
void popFront(T)(ref T[] a) { a = a[1 .. $]; }
R find(R, T)(R haystack, T needle)
if (is(typeof(haystack.front != needle) == bool))
{
while (!haystack.empty && haystack.front != needle)
{
haystack.popFront();
}
return haystack;
}
unittest
{
writeln(find([1, 2, 3], 2.0));
assert(find([1, 2, 3], 1.0));
}