Nvwa  1.1
Classes | Namespaces | Functions
functional.h File Reference

Utility templates for functional programming style. More...

#include <functional>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "_nvwa.h"
Include dependency graph for functional.h:

Go to the source code of this file.

Classes

class  nvwa::bad_optional_access
 Class for bad optional access exception. More...
 
class  nvwa::optional< _Tp >
 Class for optional values. More...
 

Namespaces

 nvwa
 Namespace of the nvwa project.
 

Functions

template<typename _Fn >
auto nvwa::lift_optional (_Fn &&f)
 Lifts a function so that it takes optionals and returns an optional. More...
 
template<typename _Fn , typename... _Opt>
constexpr auto nvwa::apply (_Fn &&f, _Opt &&... args) -> decltype(has_value(args...), optional< std::decay_t< decltype(f(std::forward< _Opt >(args).value()...))>>())
 Applies a function to the values of optionals if they are all valid. More...
 
template<typename _Fn , class _Tuple >
constexpr auto nvwa::apply (_Fn &&f, _Tuple &&t) -> decltype(detail::tuple_apply_impl(std::forward< _Fn >(f), std::forward< _Tuple >(t), std::make_index_sequence< std::tuple_size< std::decay_t< _Tuple >>::value >()))
 Applies the function with all elements of the typle as arguments. More...
 
template<typename _Fn , typename _T1 , typename _T2 >
constexpr auto nvwa::fmap (_Fn &&f, const std::pair< _T1, _T2 > &args)
 Applies a function to both elements of a pair, and makes the results a pair. More...
 
template<typename _Fn , typename... _Targs>
constexpr auto nvwa::fmap (_Fn &&f, const std::tuple< _Targs... > &args)
 Applies a function to all elements of a tuple, and makes the results a tuple. More...
 
template<template< typename, typename > class _OutCont = std::vector, template< typename > class _Alloc = std::allocator, typename _Fn , class _Rng >
constexpr auto nvwa::fmap (_Fn &&f, _Rng &&inputs) -> decltype(detail::adl_begin(inputs), detail::adl_end(inputs), _OutCont< std::decay_t< decltype(f(*detail::adl_begin(inputs)))>, _Alloc< std::decay_t< decltype(f(*detail::adl_begin(inputs)))>>>())
 Applies a function to each element in the input range. More...
 
template<typename _Rs , typename _Fn , typename... _Targs>
constexpr auto nvwa::reduce (_Fn &&f, const std::tuple< _Targs... > &args, _Rs &&value)
 Applies a function cumulatively to all elements of a tuple. More...
 
template<typename _Fn , class _Rng >
constexpr auto nvwa::reduce (_Fn &&f, _Rng &&inputs)
 Applies a function cumulatively to elements in the input range. More...
 
template<typename _Rs , typename _Fn , typename _Iter >
constexpr _Rs && nvwa::reduce (_Fn &&f, _Rs &&value, _Iter begin, _Iter end)
 Applies a function cumulatively to a range. More...
 
template<typename _Rs , typename _Fn , class _Rng >
constexpr auto nvwa::reduce (_Fn &&f, _Rng &&inputs, _Rs &&initval) -> decltype(f(initval, *detail::adl_begin(inputs)))
 Applies a function cumulatively to elements in the input range. More...
 
template<typename _T1 , typename _T2 , typename _Fn >
constexpr auto nvwa::wrap_args_as_pair (_Fn &&f)
 Makes a two-argument function accept a pair instead. More...
 
template<typename _Tuple , typename _Fn >
constexpr auto nvwa::wrap_args_as_tuple (_Fn &&f)
 Makes a function accept a tuple as its arguments. More...
 
template<typename _Tp >
constexpr _Tp nvwa::pipeline (_Tp &&data)
 Returns the data intact to terminate the recursion.
 
template<typename _Tp , typename _Fn , typename... _Fargs>
decltype(auto) constexpr nvwa::pipeline (_Tp &&data, _Fn &&f, _Fargs &&... args)
 Applies the functions in the arguments to the data consecutively. More...
 
auto nvwa::compose ()
 Constructs a function (object) that composes the passed functions. More...
 
template<typename _Fn >
auto nvwa::compose (_Fn f)
 Constructs a function (object) that composes the passed functions. More...
 
template<typename _Fn , typename... _Fargs>
auto nvwa::compose (_Fn f, _Fargs... args)
 Constructs a function (object) that composes the passed functions. More...
 
template<typename _Rs , typename _Tp >
std::function< _Rs(_Tp)> nvwa::fix_simple (std::function< _Rs(std::function< _Rs(_Tp)>, _Tp)> f)
 Generates the fixed point using the simple fixed-point combinator. More...
 
template<typename _Rs , typename _Tp >
std::function< _Rs(_Tp)> nvwa::fix_simple (std::function< std::function< _Rs(_Tp)>(std::function< _Rs(_Tp)>)> f)
 Generates the fixed point using the simple fixed-point combinator. More...
 
template<typename _Rs , typename _Tp >
std::function< _Rs(_Tp)> nvwa::fix_curry (std::function< std::function< _Rs(_Tp)>(std::function< _Rs(_Tp)>)> f)
 Generates the fixed point using the Curry-style fixed-point combinator. More...
 
template<typename _Rs , typename... _Targs>
auto nvwa::make_curry (std::function< _Rs(_Targs...)> f)
 Makes a curried function. More...
 
template<typename _Rs , typename... _Targs>
auto nvwa::make_curry (_Rs(*f)(_Targs...))
 Makes a curried function. More...
 
template<typename _FnType , typename _Fn >
auto nvwa::make_curry (_Fn &&f)
 Makes a curried function. More...
 

Detailed Description

Utility templates for functional programming style.

Using this file requires a C++14-compliant compiler.

Date
2016-11-06