typetui 0.2.0

A terminal-based typing test.
Documentation
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
#include <functional>

template<typename T>
std::vector<T> filter(const std::vector<T>& input, std::function<bool(const T&)> predicate) {
    std::vector<T> result;
    std::copy_if(input.begin(), input.end(), std::back_inserter(result), predicate);
    return result;
}

template<typename T, typename Func>
std::vector<std::invoke_result_t<Func, T>> map(const std::vector<T>& input, Func&& fn) {
    std::vector<std::invoke_result_t<Func, T>> result;
    result.reserve(input.size());
    std::transform(input.begin(), input.end(), std::back_inserter(result), fn);
    return result;
}

template<typename T, typename R>
R reduce(const std::vector<T>& input, R initial, std::function<R(R, const T&)> fn) {
    return std::accumulate(input.begin(), input.end(), initial, fn);
}

template<typename T>
bool any_of(const std::vector<T>& input, std::function<bool(const T&)> predicate) {
    return std::any_of(input.begin(), input.end(), predicate);
}

template<typename T>
bool all_of(const std::vector<T>& input, std::function<bool(const T&)> predicate) {
    return std::all_of(input.begin(), input.end(), predicate);
}

template<typename T>
std::vector<T> sort(std::vector<T> input) {
    std::sort(input.begin(), input.end());
    return input;
}

template<typename T, typename Compare>
std::vector<T> sort_by(std::vector<T> input, Compare comp) {
    std::sort(input.begin(), input.end(), comp);
    return input;
}

template<typename T>
std::unique_ptr<T> find_first(const std::vector<T>& input, std::function<bool(const T&)> predicate) {
    auto it = std::find_if(input.begin(), input.end(), predicate);
    if (it != input.end()) {
        return std::make_unique<T>(*it);
    }
    return nullptr;
}

int binary_search(const std::vector<int>& sorted, int target) {
    auto it = std::lower_bound(sorted.begin(), sorted.end(), target);
    if (it != sorted.end() && *it == target) {
        return static_cast<int>(std::distance(sorted.begin(), it));
    }
    return -1;
}

template<typename T>
void quicksort(std::vector<T>& arr, int low, int high) {
    if (low < high) {
        T pivot = arr[high];
        int i = low - 1;
        for (int j = low; j < high; j++) {
            if (arr[j] <= pivot) {
                i++;
                std::swap(arr[i], arr[j]);
            }
        }
        std::swap(arr[i + 1], arr[high]);
        int pi = i + 1;
        quicksort(arr, low, pi - 1);
        quicksort(arr, pi + 1, high);
    }
}

template<typename T>
int binary_search_recursive(const std::vector<T>& arr, int left, int right, const T& target) {
    if (right >= left) {
        int mid = left + (right - left) / 2;
        if (arr[mid] == target) return mid;
        if (arr[mid] > target) return binary_search_recursive(arr, left, mid - 1, target);
        return binary_search_recursive(arr, mid + 1, right, target);
    }
    return -1;
}

template<typename T>
void reverse_inplace(std::vector<T>& vec) {
    int left = 0, right = static_cast<int>(vec.size()) - 1;
    while (left < right) {
        std::swap(vec[left], vec[right]);
        left++;
        right--;
    }
}

template<typename T>
std::vector<T> merge_sorted(const std::vector<T>& a, const std::vector<T>& b) {
    std::vector<T> result;
    result.reserve(a.size() + b.size());
    std::merge(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(result));
    return result;
}

template<typename T>
std::vector<T> unique_elements(std::vector<T> input) {
    std::sort(input.begin(), input.end());
    input.erase(std::unique(input.begin(), input.end()), input.end());
    return input;
}

int main() {
    std::vector<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    auto evens = filter(numbers, [](int n) { return n % 2 == 0; });
    auto doubled = map(numbers, [](int n) { return n * 2; });
    auto sum = reduce(numbers, 0, [](int acc, int n) { return acc + n; });

    bool has_even = any_of(numbers, [](int n) { return n % 2 == 0; });
    bool all_positive = all_of(numbers, [](int n) { return n > 0; });

    std::cout << "Sum: " << sum << "\n";
    std::cout << "Has even: " << has_even << "\n";

    std::vector<int> to_sort = {64, 34, 25, 12, 22, 11, 90};
    quicksort(to_sort, 0, static_cast<int>(to_sort.size()) - 1);

    std::vector<int> sorted = {1, 3, 5, 7, 9};
    int index = binary_search(sorted, 5);
    std::cout << "Found at index: " << index << "\n";

    return 0;
}