rangeless::fn
Filtering

Functions

template<typename P >
impl::take_while< P > rangeless::fn::take_while (P pred)
 Yield elements until pred evaluates to false. More...
 
impl::take_while< impl::call_count_ltrangeless::fn::take_first (size_t n=1)
 Yield first n elements. More...
 
impl::take_last rangeless::fn::take_last (size_t n=1)
 Yield last n elements. More...
 
template<typename P >
impl::drop_while< P > rangeless::fn::drop_while (P pred)
 Drop elements until pred evaluates to false. More...
 
impl::drop_while< impl::call_count_ltrangeless::fn::drop_first (size_t n=1)
 Drop first n elements. More...
 
impl::drop_last rangeless::fn::drop_last (size_t n=1)
 Drop last n elements. More...
 
template<typename P >
impl::where< P > rangeless::fn::where (P pred)
 Filter elements. More...
 
template<typename SortedForwardRange , typename F >
impl::where< impl::in_sorted_by< SortedForwardRange, F > > rangeless::fn::where_in_sorted_by (const SortedForwardRange &r, F key_fn)
 
template<typename SortedForwardRange >
impl::where< impl::in_sorted_by< SortedForwardRange, by::identity > > rangeless::fn::where_in_sorted (const SortedForwardRange &r)
 Intersect with a sorted range. More...
 
template<typename SortedForwardRange , typename F >
impl::where< impl::in_sorted_by< SortedForwardRange, F > > rangeless::fn::where_not_in_sorted_by (const SortedForwardRange &r, F key_fn)
 
template<typename SortedForwardRange >
impl::where< impl::in_sorted_by< SortedForwardRange, by::identity > > rangeless::fn::where_not_in_sorted (const SortedForwardRange &r)
 Subtract a sorted range. More...
 
template<typename F >
impl::where_max_by< F > rangeless::fn::where_max_by (F key_fn)
 Filter elements to those having maximum value of fn. More...
 
impl::where_max_by< by::identityrangeless::fn::where_max ()
 
template<typename F >
impl::where_max_by< F > rangeless::fn::where_min_by (F key_fn)
 
impl::where_max_by< by::identityrangeless::fn::where_min ()
 
template<typename Pred >
impl::exists_where< Pred > rangeless::fn::exists_where (Pred p)
 

Detailed Description

Function Documentation

◆ drop_first()

impl::drop_while<impl::call_count_lt> rangeless::fn::drop_first ( size_t  n = 1)
inline

Drop first n elements.

Definition at line 3859 of file fn.hpp.

◆ drop_last()

impl::drop_last rangeless::fn::drop_last ( size_t  n = 1)
inline

Drop last n elements.

Buffering space requirements for seq: O(n).

Definition at line 3867 of file fn.hpp.

◆ drop_while()

template<typename P >
impl::drop_while<P> rangeless::fn::drop_while ( pred)

Drop elements until pred evaluates to false.

Definition at line 3853 of file fn.hpp.

◆ exists_where()

template<typename Pred >
impl::exists_where<Pred> rangeless::fn::exists_where ( Pred  p)
const bool any = vals % fn::exists_where(pred);
const bool none = vals % !fn::exists_where(pred);
const bool all = vals % !fn::exists_where(not_pred);

Definition at line 3997 of file fn.hpp.

◆ take_first()

impl::take_while<impl::call_count_lt> rangeless::fn::take_first ( size_t  n = 1)
inline

Yield first n elements.

Definition at line 3838 of file fn.hpp.

◆ take_last()

impl::take_last rangeless::fn::take_last ( size_t  n = 1)
inline

Yield last n elements.

Buffering space requirements for seq: O(n).

Definition at line 3846 of file fn.hpp.

◆ take_while()

template<typename P >
impl::take_while<P> rangeless::fn::take_while ( pred)

Yield elements until pred evaluates to false.

Definition at line 3832 of file fn.hpp.

◆ where()

template<typename P >
impl::where<P> rangeless::fn::where ( pred)

Filter elements.

Returns a unary function-object.

// 1) If arg is a container passed by lvalue-reference,
// return a copy of the container with elements
// satisfying the predicate:
auto nonempty_strs = strs % fn::where([](auto&& s) { return !s.empty(); });
// 2.1) If arg is a sequence container passed by rvalue,
// remove the unsatisfying elements using erase-remove idiom and return the container.
//
// 2.2) If arg is a container having equal_range method (sets, associative containers, etc),
// remove the unsatisfying elements using iterate-erase idiom and return the container.
strs = std::move(strs) % fn::where([](auto&& s) { return !s.empty(); });
// 3) If arg is a seq<G>, return adapted seq<...> that shall
// yield elements satisfying the predicate:
auto res = fn::seq([i = 0]
{
return i < 5 ? i++ : fn::end_seq();
}) % fn::where( [](int x) { return x > 2; }) // 3, 4
% fn::transform( [](int x) { return x + 1; }) // 4, 5
% fn::foldl_d( [](int out, int in) { return out*10 + in; });
VERIFY(res == 45);

Definition at line 3903 of file fn.hpp.

◆ where_in_sorted()

template<typename SortedForwardRange >
impl::where<impl::in_sorted_by<SortedForwardRange, by::identity> > rangeless::fn::where_in_sorted ( const SortedForwardRange &  r)

Intersect with a sorted range.

elems %= fn::where_in_sorted(whitelist);

Definition at line 3920 of file fn.hpp.

◆ where_in_sorted_by()

template<typename SortedForwardRange , typename F >
impl::where<impl::in_sorted_by<SortedForwardRange, F> > rangeless::fn::where_in_sorted_by ( const SortedForwardRange &  r,
key_fn 
)
See also
where_in_sorted

Definition at line 3910 of file fn.hpp.

◆ where_max()

impl::where_max_by<by::identity> rangeless::fn::where_max ( )
inline

Definition at line 3973 of file fn.hpp.

◆ where_max_by()

template<typename F >
impl::where_max_by<F> rangeless::fn::where_max_by ( key_fn)

Filter elements to those having maximum value of fn.

// 1) If Arg is a container (taken by value), find the max-element
// and return a vector of max-elements (moved-from the original container).
strs = std::move(strs) % fn::where_max_by([](auto&& s) { return s.size(); });
// 2) If Arg is a seq, iterates the seq and returns
// std::vector<seq<...>::value_type> containing maximal elements.
auto res = fn::seq([i = 0]
{
return i < 5 ? i++ : fn::end_seq();
}) % fn::where_max_by([](int x) { return x % 2; });
VERIFY((res == vec_t{{1, 3}}));

Buffering space requirements for seq: O(k), where k = maximum number of max-elements in a prefix of seq over all prefixes of seq. e.g.
[1,0,1,1,0,1,1,9]: k = 5
[1,3,1,1,3,1,1,9]: k = 2

Definition at line 3968 of file fn.hpp.

◆ where_min()

impl::where_max_by<by::identity> rangeless::fn::where_min ( )
inline

Definition at line 3986 of file fn.hpp.

◆ where_min_by()

template<typename F >
impl::where_max_by<F> rangeless::fn::where_min_by ( key_fn)

Filter elements to those having maximum value of fn.

See also
where_max_by

Definition at line 3981 of file fn.hpp.

◆ where_not_in_sorted()

template<typename SortedForwardRange >
impl::where<impl::in_sorted_by<SortedForwardRange, by::identity> > rangeless::fn::where_not_in_sorted ( const SortedForwardRange &  r)

Subtract a sorted range.

elems %= fn::where_not_in_sorted(blacklist);

Definition at line 3937 of file fn.hpp.

◆ where_not_in_sorted_by()

template<typename SortedForwardRange , typename F >
impl::where<impl::in_sorted_by<SortedForwardRange, F> > rangeless::fn::where_not_in_sorted_by ( const SortedForwardRange &  r,
key_fn 
)
See also
where_not_in_sorted

Definition at line 3927 of file fn.hpp.