proxygen
folly::gen::detail::Reduce< Reducer > Class Template Reference

#include <Base-inl.h>

Inheritance diagram for folly::gen::detail::Reduce< Reducer >:
folly::gen::Operator< Reduce< Reducer > > folly::gen::FBounded< Self >

Public Member Functions

 Reduce ()=default
 
 Reduce (Reducer reducer)
 
template<class Source , class Value , class StorageType = typename std::decay<Value>::type>
Optional< StorageType > compose (const GenImpl< Value, Source > &source) const
 
- Public Member Functions inherited from folly::gen::Operator< Reduce< Reducer > >
ResultGen compose (const GenImpl< Value, Source > &source) const
 
- Public Member Functions inherited from folly::gen::FBounded< Self >
const Self & self () const
 
Self & self ()
 

Private Attributes

Reducer reducer_
 

Additional Inherited Members

- Protected Member Functions inherited from folly::gen::Operator< Reduce< Reducer > >
 Operator ()=default
 
 Operator (Operator &&) noexcept=default
 
 Operator (const Operator &)=default
 
Operatoroperator= (Operator &&) noexcept=default
 
Operatoroperator= (const Operator &)=default
 

Detailed Description

template<class Reducer>
class folly::gen::detail::Reduce< Reducer >

Reduce - Functional reduce, for recursively combining values from a source using a reducer function until there is only one item left. Useful for combining values when an empty sequence doesn't make sense.

This type is primarily used through the 'reduce' helper method, like:

sring longest = from(names) | reduce([](string&& best, string& current) { return best.size() >= current.size() ? best : current; });

Definition at line 2099 of file Base-inl.h.

Constructor & Destructor Documentation

template<class Reducer >
folly::gen::detail::Reduce< Reducer >::Reduce ( )
default
template<class Reducer >
folly::gen::detail::Reduce< Reducer >::Reduce ( Reducer  reducer)
inlineexplicit

Definition at line 2104 of file Base-inl.h.

References type, and testing::Value().

2104 : reducer_(std::move(reducer)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Function Documentation

template<class Reducer >
template<class Source , class Value , class StorageType = typename std::decay<Value>::type>
Optional<StorageType> folly::gen::detail::Reduce< Reducer >::compose ( const GenImpl< Value, Source > &  source) const
inline

Definition at line 2110 of file Base-inl.h.

References folly::Optional< Value >::get_pointer(), folly::gen::move, and v.

2110  {
2111  static_assert(!Source::infinite, "Cannot reduce infinite source");
2112  Optional<StorageType> accum;
2113  source | [&](Value v) {
2114  if (auto target = accum.get_pointer()) {
2115  *target = reducer_(std::move(*target), std::forward<Value>(v));
2116  } else {
2117  accum = std::forward<Value>(v);
2118  }
2119  };
2120  return accum;
2121  }
auto v
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool Value(const T &value, M matcher)

Member Data Documentation

template<class Reducer >
Reducer folly::gen::detail::Reduce< Reducer >::reducer_
private

Definition at line 2100 of file Base-inl.h.


The documentation for this class was generated from the following file: