|
|
@@ -1,6 +1,7 @@
|
|
|
#pragma once
|
|
|
|
|
|
#include <algorithm>
|
|
|
+#include <optional>
|
|
|
#include <memory>
|
|
|
#include <numeric>
|
|
|
#include <vector>
|
|
|
@@ -125,6 +126,19 @@ namespace stream {
|
|
|
std::copy(begin(), end(), std::inserter(coll, coll.end()));
|
|
|
return coll;
|
|
|
}
|
|
|
+
|
|
|
+ std::optional<value_type> first() const {
|
|
|
+ return begin() != end() ? std::optional(*begin()) : std::nullopt;
|
|
|
+ }
|
|
|
+
|
|
|
+ template <typename F>
|
|
|
+ bool none(F &&pred) const { return std::none_of(begin(), end(), pred); }
|
|
|
+
|
|
|
+ template <typename F>
|
|
|
+ bool all(F &&pred) const { return std::all_of(begin(), end(), pred); }
|
|
|
+
|
|
|
+ template <typename F>
|
|
|
+ bool any(F &&pred) const { return std::any_of(begin(), end(), pred); }
|
|
|
|
|
|
template <typename F>
|
|
|
value_type accumulate(F && fold, value_type const & accum) const {
|
|
|
@@ -144,6 +158,14 @@ namespace stream {
|
|
|
template <typename F> stream_base<T> filter(F && func) const &;
|
|
|
template <typename F>
|
|
|
stream_base<traits::fmapped_t<T, F>> flatmap(F && func) const &;
|
|
|
+
|
|
|
+ auto keys() const & {
|
|
|
+ return map([](auto &kv) -> decltype(auto) { return kv.first; });
|
|
|
+ }
|
|
|
+
|
|
|
+ auto values() const & {
|
|
|
+ return map([](auto &kv) -> decltype(auto) { return kv.second; });
|
|
|
+ }
|
|
|
|
|
|
template <typename F>
|
|
|
stream_base<traits::mapped_t<T, F>> map(F && func) &&;
|