Skip to content

Commit

Permalink
s/compress/fold/g
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Sep 8, 2017
1 parent 4b45fb5 commit bb3282c
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 224 deletions.
4 changes: 2 additions & 2 deletions doc/src/adaptors.rst
Expand Up @@ -8,7 +8,7 @@ Function Adaptors
../../include/fit/compose
../../include/fit/conditional
../../include/fit/combine
../../include/fit/compress
../../include/fit/fold
../../include/fit/decorate
../../include/fit/fix
../../include/fit/flip
Expand All @@ -24,7 +24,7 @@ Function Adaptors
../../include/fit/protect
../../include/fit/result
../../include/fit/reveal
../../include/fit/reverse_compress
../../include/fit/reverse_fold
../../include/fit/rotate
../../include/fit/static
../../include/fit/unpack
6 changes: 3 additions & 3 deletions doc/src/point_free.md
Expand Up @@ -74,14 +74,14 @@ Another example, say we would like to write a varidiac version of `max`. We coul
return std::max(x, max(y, xs...));
}

With point-free style programming, we can recognize this is a [fold](https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29), and write it using the [`compress`](/include/fit/compress) adaptor, which will do a fold over the variadic parameters:
With point-free style programming, we can recognize this is a [fold](https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29), and write it using the [`fold`](/include/fit/fold) adaptor, which will do a fold over the variadic parameters:

FIT_STATIC_FUNCTION(max) = compress(FIT_LIFT(std::max));
FIT_STATIC_FUNCTION(max) = fold(FIT_LIFT(std::max));

[`FIT_LIFT`](/include/fit/lift) is used to grab the entire overload set of `std::max` function, which is needed since `std::max` is templated and we want the variadic `std::max` function to handle any types as well. So now it can be called like this:

auto n = max(1, 2, 4, 3); // Returns 4
auto m = max(0.1, 0.2, 0.5, 0.4); // Returns 0.5

By using [`compress`](/include/fit/compress), `max(1, 2, 4, 3)` will call `std::max` like `std::max(std::max(std::max(1, 2), 4), 3)` and `max(0.1, 0.2, 0.5, 0.4)` will be called like `std::max(std::max(std::max(0.1, 0.2), 0.5), 0.4)`.
By using [`fold`](/include/fit/fold), `max(1, 2, 4, 3)` will call `std::max` like `std::max(std::max(std::max(1, 2), 4), 3)` and `max(0.1, 0.2, 0.5, 0.4)` will be called like `std::max(std::max(std::max(0.1, 0.2), 0.5), 0.4)`.

4 changes: 2 additions & 2 deletions example/example.h
Expand Up @@ -17,7 +17,7 @@
#include <fit/capture.hpp>
#include <fit/combine.hpp>
#include <fit/compose.hpp>
#include <fit/compress.hpp>
#include <fit/fold.hpp>
#include <fit/conditional.hpp>
#include <fit/construct.hpp>
#include <fit/decay.hpp>
Expand Down Expand Up @@ -49,7 +49,7 @@
#include <fit/result.hpp>
#include <fit/returns.hpp>
#include <fit/reveal.hpp>
#include <fit/reverse_compress.hpp>
#include <fit/reverse_fold.hpp>
#include <fit/rotate.hpp>
#include <fit/static.hpp>
#include <fit/tap.hpp>
Expand Down
2 changes: 1 addition & 1 deletion example/pointfree.cpp
Expand Up @@ -12,7 +12,7 @@ using namespace fit;
FIT_STATIC_FUNCTION(simple_print) = FIT_LIFT(std::ref(std::cout) << _);
FIT_STATIC_FUNCTION(print) = by(simple_print);
FIT_STATIC_FUNCTION(print_lines) = by(flow(simple_print, _ << std::integral_constant<char, '\n'>{}));
FIT_STATIC_FUNCTION(max) = compress(FIT_LIFT(std::max));
FIT_STATIC_FUNCTION(max) = fold(FIT_LIFT(std::max));

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion example/sequence.cpp
Expand Up @@ -23,7 +23,7 @@ FIT_STATIC_LAMBDA_FUNCTION(tuple_for_each) = [](auto&& sequence, auto f)
// Fold over tuple using a f as the binary operator
FIT_STATIC_LAMBDA_FUNCTION(tuple_fold) = [](auto&& sequence, auto f)
{
return unpack(compress(f))(std::forward<decltype(sequence)>(sequence));
return unpack(fold(f))(std::forward<decltype(sequence)>(sequence));
};
// Concat multiple tuples
FIT_STATIC_FUNCTION(tuple_cat) = unpack(construct<std::tuple>());
Expand Down
4 changes: 2 additions & 2 deletions include/fit.hpp
Expand Up @@ -17,7 +17,7 @@
#include <fit/capture.hpp>
#include <fit/combine.hpp>
#include <fit/compose.hpp>
#include <fit/compress.hpp>
#include <fit/fold.hpp>
#include <fit/conditional.hpp>
#include <fit/construct.hpp>
#include <fit/decay.hpp>
Expand Down Expand Up @@ -49,7 +49,7 @@
#include <fit/result.hpp>
#include <fit/returns.hpp>
#include <fit/reveal.hpp>
#include <fit/reverse_compress.hpp>
#include <fit/reverse_fold.hpp>
#include <fit/rotate.hpp>
#include <fit/static.hpp>
#include <fit/tap.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/fit/apply.hpp
Expand Up @@ -26,7 +26,7 @@
/// ---------
///
/// assert(apply(f)(xs...) == f(xs...));
/// assert(compress(apply, f)(x, y, z) == f(x)(y)(z));
/// assert(fold(apply, f)(x, y, z) == f(x)(y)(z));
///
/// Requirements
/// ------------
Expand Down
38 changes: 19 additions & 19 deletions include/fit/compress.hpp → include/fit/fold.hpp
@@ -1,20 +1,20 @@
/*=============================================================================
Copyright (c) 2015 Paul Fultz II
compress.h
fold.h
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/

#ifndef FIT_GUARD_COMPRESS_H
#define FIT_GUARD_COMPRESS_H
#ifndef FIT_GUARD_FOLD_H
#define FIT_GUARD_FOLD_H

/// compress
/// fold
/// ========
///
/// Description
/// -----------
///
/// The `compress` function adaptor uses a binary function to apply a
/// The `fold` function adaptor uses a binary function to apply a
/// [fold](https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29)
/// operation to the arguments passed to the function. Additionally, an
/// optional initial state can be provided, otherwise the first argument is
Expand All @@ -27,18 +27,18 @@
/// --------
///
/// template<class F, class State>
/// constexpr compress_adaptor<F, State> compress(F f, State s);
/// constexpr fold_adaptor<F, State> fold(F f, State s);
///
/// template<class F>
/// constexpr compress_adaptor<F> compress(F f);
/// constexpr fold_adaptor<F> fold(F f);
///
/// Semantics
/// ---------
///
/// assert(compress(f, z)() == z);
/// assert(compress(f, z)(x, xs...) == compress(f, f(z, x))(xs...));
/// assert(compress(f)(x) == x);
/// assert(compress(f)(x, y, xs...) == compress(f)(f(x, y), xs...));
/// assert(fold(f, z)() == z);
/// assert(fold(f, z)(x, xs...) == fold(f, f(z, x))(xs...));
/// assert(fold(f)(x) == x);
/// assert(fold(f)(x, y, xs...) == fold(f)(f(x, y), xs...));
///
/// Requirements
/// ------------
Expand Down Expand Up @@ -67,7 +67,7 @@
/// }
/// };
/// int main() {
/// assert(fit::compress(max_f())(2, 3, 4, 5) == 5);
/// assert(fit::fold(max_f())(2, 3, 4, 5) == 5);
/// }
///
/// References
Expand Down Expand Up @@ -106,11 +106,11 @@ struct v_fold
}

template<class F, class State=void>
struct compress_adaptor
struct fold_adaptor
: detail::compressed_pair<detail::callable_base<F>, State>
{
typedef detail::compressed_pair<detail::callable_base<F>, State> base_type;
FIT_INHERIT_CONSTRUCTOR(compress_adaptor, base_type)
FIT_INHERIT_CONSTRUCTOR(fold_adaptor, base_type)

template<class... Ts>
constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
Expand All @@ -124,7 +124,7 @@ struct compress_adaptor
return this->second(xs...);
}

FIT_RETURNS_CLASS(compress_adaptor);
FIT_RETURNS_CLASS(fold_adaptor);

template<class... Ts>
constexpr FIT_SFINAE_RESULT(detail::v_fold, id_<const detail::callable_base<F>&>, id_<State>, id_<Ts>...)
Expand All @@ -140,18 +140,18 @@ struct compress_adaptor


template<class F>
struct compress_adaptor<F, void>
struct fold_adaptor<F, void>
: detail::callable_base<F>
{
FIT_INHERIT_CONSTRUCTOR(compress_adaptor, detail::callable_base<F>)
FIT_INHERIT_CONSTRUCTOR(fold_adaptor, detail::callable_base<F>)

template<class... Ts>
constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
{
return fit::always_ref(*this)(xs...);
}

FIT_RETURNS_CLASS(compress_adaptor);
FIT_RETURNS_CLASS(fold_adaptor);

template<class... Ts>
constexpr FIT_SFINAE_RESULT(detail::v_fold, id_<const detail::callable_base<F>&>, id_<Ts>...)
Expand All @@ -164,7 +164,7 @@ struct compress_adaptor<F, void>
)
};

FIT_DECLARE_STATIC_VAR(compress, detail::make<compress_adaptor>);
FIT_DECLARE_STATIC_VAR(fold, detail::make<fold_adaptor>);

} // namespace fit

Expand Down
38 changes: 19 additions & 19 deletions include/fit/reverse_compress.hpp → include/fit/reverse_fold.hpp
@@ -1,20 +1,20 @@
/*=============================================================================
Copyright (c) 2015 Paul Fultz II
reverse_compress.h
reverse_fold.h
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/

#ifndef FIT_GUARD_REVERSE_COMPRESS_H
#define FIT_GUARD_REVERSE_COMPRESS_H
#ifndef FIT_GUARD_REVERSE_FOLD_H
#define FIT_GUARD_REVERSE_FOLD_H

/// reverse_compress
/// reverse_fold
/// ========
///
/// Description
/// -----------
///
/// The `reverse_compress` function adaptor uses a binary function to apply a
/// The `reverse_fold` function adaptor uses a binary function to apply a
/// reverse [fold]
/// (https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29)(ie right
/// fold in functional programming terms) operation to the arguments passed to
Expand All @@ -28,18 +28,18 @@
/// --------
///
/// template<class F, class State>
/// constexpr reverse_compress_adaptor<F, State> reverse_compress(F f, State s);
/// constexpr reverse_fold_adaptor<F, State> reverse_fold(F f, State s);
///
/// template<class F>
/// constexpr reverse_compress_adaptor<F> reverse_compress(F f);
/// constexpr reverse_fold_adaptor<F> reverse_fold(F f);
///
/// Semantics
/// ---------
///
/// assert(reverse_compress(f, z)() == z);
/// assert(reverse_compress(f, z)(x, xs...) == f(reverse_compress(f, z)(xs...), x));
/// assert(reverse_compress(f)(x) == x);
/// assert(reverse_compress(f)(x, xs...) == f(reverse_compress(f)(xs...), x));
/// assert(reverse_fold(f, z)() == z);
/// assert(reverse_fold(f, z)(x, xs...) == f(reverse_fold(f, z)(xs...), x));
/// assert(reverse_fold(f)(x) == x);
/// assert(reverse_fold(f)(x, xs...) == f(reverse_fold(f)(xs...), x));
///
/// Requirements
/// ------------
Expand Down Expand Up @@ -69,7 +69,7 @@
/// };
///
/// int main() {
/// assert(fit::reverse_compress(max_f())(2, 3, 4, 5) == 5);
/// assert(fit::reverse_fold(max_f())(2, 3, 4, 5) == 5);
/// }
///
/// References
Expand Down Expand Up @@ -108,11 +108,11 @@ struct v_reverse_fold
}

template<class F, class State=void>
struct reverse_compress_adaptor
struct reverse_fold_adaptor
: detail::compressed_pair<detail::callable_base<F>, State>
{
typedef detail::compressed_pair<detail::callable_base<F>, State> base_type;
FIT_INHERIT_CONSTRUCTOR(reverse_compress_adaptor, base_type)
FIT_INHERIT_CONSTRUCTOR(reverse_fold_adaptor, base_type)

template<class... Ts>
constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
Expand All @@ -126,7 +126,7 @@ struct reverse_compress_adaptor
return this->second(xs...);
}

FIT_RETURNS_CLASS(reverse_compress_adaptor);
FIT_RETURNS_CLASS(reverse_fold_adaptor);

template<class... Ts>
constexpr FIT_SFINAE_RESULT(detail::v_reverse_fold, id_<const detail::callable_base<F>&>, id_<State>, id_<Ts>...)
Expand All @@ -142,18 +142,18 @@ struct reverse_compress_adaptor


template<class F>
struct reverse_compress_adaptor<F, void>
struct reverse_fold_adaptor<F, void>
: detail::callable_base<F>
{
FIT_INHERIT_CONSTRUCTOR(reverse_compress_adaptor, detail::callable_base<F>)
FIT_INHERIT_CONSTRUCTOR(reverse_fold_adaptor, detail::callable_base<F>)

template<class... Ts>
constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const noexcept
{
return fit::always_ref(*this)(xs...);
}

FIT_RETURNS_CLASS(reverse_compress_adaptor);
FIT_RETURNS_CLASS(reverse_fold_adaptor);

template<class... Ts>
constexpr FIT_SFINAE_RESULT(detail::v_reverse_fold, id_<const detail::callable_base<F>&>, id_<Ts>...)
Expand All @@ -166,7 +166,7 @@ struct reverse_compress_adaptor<F, void>
)
};

FIT_DECLARE_STATIC_VAR(reverse_compress, detail::make<reverse_compress_adaptor>);
FIT_DECLARE_STATIC_VAR(reverse_fold, detail::make<reverse_fold_adaptor>);

} // namespace fit

Expand Down

0 comments on commit bb3282c

Please sign in to comment.