Giter VIP home page Giter VIP logo

expected's People

Contributors

faithandbrave avatar garyfurnish avatar hrobeers avatar jenkins-nedprod avatar ptal avatar viboes avatar vtnerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

expected's Issues

[Monads] remove expected_like

The category expected_like has no sense. Either we found a better concept and replace it or we just don't use any concept and do the specialization for expected and optional specifically.

[Monads] Generalize the value_or algorithm

boost/expected/algorithms/value_or.hpp contains a function that can be generalized to other monads, as it is the case of expected<T>, optional<T> and future<T>.

The first question is in which namespace this function must be defined.
The second is if it is worth defining a default for classes that or forward the call to a member function value_or.

Cleanup when BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined

There are a lot of check if BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined but we don't provide an alternative yet. Maybe we should stick to C++ compilers for the time been. We will manage this when we will move to C++98 compilers.

[Monads] Create a rebindable concept

// features
template <class M, class Traits = rebindable_traits_t<M> > 
using value_type = typename Traits :: template value_type<M>; 

template <class M, class U, class Traits = rebindable_traits_t<M > > 
using rebind = typename Traits :: template rebind<M, U>;

[Monads] Generalize the catch_exception function

boost/expected/algorithms/catch_unexpected.hpp contains a function that can be generalized to all the monad_error that store an exception_ptr, as it is the case of expected<exception_ptr,T> and future<T>.

An alternative is to define this function for the error themselves, but then the user must first get the error and then do the catch_exception.

Add a catch_all adaptor

Expected can be viewed as interfacing between a monadic code and an exception-throwing code. It could be convenient to have an adaptor that catch all the exception thrown and transform then on a expected <exception_ptr, T>.

This adaptor could be used with fmap, mbind and then method.

e.mbind(catch_all(f));

[Monads] Should the default traits forward?

Currently the value_traits forward all the operation fro the default category, that is the type itself. As a concept contains semantic constraints in addition of the syntactic ones, it would be better if the model designer states explicitly that the forward is correct way to map the type.

So I purpose to add a forward category and replace the default with this category.

  template <class T>
  struct value_traits : std::false_type {} ; // SFINAE friendly

  template <class T>
  struct value_traits<category::forward> : std::true_type  // SFINAE friendly
  {
    template <class M>
    static constexpr bool has_value(M&& m)
    { return m.has_value();}

    template <class M>
    static constexpr auto deref(M&& m) -> decltype(m.deref())
    { return m.deref();};

    template <class M>
    static constexpr auto get_value(M&& m) -> decltype(m.value())
    { return m.value(); };
  };

Possible to completely ignore error

boost::expected<int> fun() {
  return boost::make_expected_from_error<int>(std::runtime_error("Test Error"));
}

int main(int argc, char* argv[]) {
  fun();
}

As the above code example runs without producing any error. This shows that it's still possible to completely ignore any error conditions. http://stackoverflow.com/questions/14923346/how-would-you-use-alexandrescus-expectedt-with-void-functions addresses this.

Destructor of expected could have an assert check that triggers if the return status has been completely ignored.

Should fmap/mbind/then catch exceptions?

Expected can be viewed as interfacing between a monadic code and an exception-throwing code. It could be convenient to call a trait method when an exception is thrown inside fmap/mbind or then method. The default trait method would rethrow if the contained error type is not an exception_ptr.

Another possibility is to have different overload for the two possibilities, what do you think?

[Monads] move have_value to monads/algorithms/have_value.hpp

template< class M >
BOOST_CONSTEXPR bool have_value( M&& m )
{
  return has_value(std::forward<M>(m));
}
template< class M1, class ...Ms >
BOOST_CONSTEXPR bool have_value( M1&& m1, Ms&& ...ms )
{
  return has_value(std::forward<M1>(m1)) && have_value( std::forward<Ms>(ms)... );
}

[Monads] Generalize the has_exception algorithm

boost/expected/algorithms/has_unexpected.hpp contains a function that can be generalized to all the monad_error that store an exception_ptr, as it is the case of expected<exception_ptr,T> and future<T>.

An alternative is to define this function for the error themselves, but then the user must first get the error and then do the has_exception.

[Monads] Movex xxx_category and xxx_traits outside xxx namespace

The xxx_category and xxx_traits are currently on the xxx namespace. There is no way to get ride of the xxx_prefix and so maybe these classes could be moved outside of the namespapce xxx. Only the types and operations associated to xxx are needed on the xxx namespace to avoid ambiguity.

[Monads] Add Monad mdo operation with its default implementation

Haskell has a default implementation for this operation using mbind.

  template <class M, class T, class U>
  apply<M,U> operator>>(apply<M,T>&& m1, apply<M,U>&& m2)
  {
    return mbind(m1, [&](T& ) { return m2; });
  }

The operator >> is used in other EDSL as sequencing operator.

[Monads] Generalize the unwrap function

boost/expected/algorithms/unwrap.hpp contains a function that can be generalized to other monads, as it is the case of expected<T>, optional<T> and future<T>.

The first question is in which namespace this function must be defined.
The second is if it is worth defining a default for monads that have only one argument or forward the call to a member function unwrap.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.