i've been working with a Result clone written on top of std::expected, and, 
while i miss pretty much everything else about nim-result, ive grown to enjoy 
being able to return a bare T from a function returning Result[T,E]
    
    
    #include <expected>
    #include <string>
    using err_t = std::string;
    template<class T> using Result = std::expected<T,err_t>;
    using err = std::unexpected<err_t>;
    
    Result<int> foo(bool x){
        if (x)
          return err("oh noes");
        else
          return 5;
    }
    
    Run

if you've got a standard error type in your project like
    
    
    type R[T] = Result[T,string]
    
    
    Run

then you can have that implicit conversion, too, for good or ill, with
    
    
    converter toR[T](x:T):R[T] = ok(x)
    
    proc foo(x:bool):Result[int,string] =
      if x:
        err("oh noes")
      else:
        5
    
    
    Run

but embracing strict typing is more the Nim way

Reply via email to