struct Ok(T)

Overview

Result Ok.

Defined in:

result.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Result(T)

err? : Bool err?, ok? : Bool ok?, state : Tuple(Symbol, Symbol, T) state, status : Symbol status, status?(s : Symbol) : Bool status?, type : Symbol type, unwrap unwrap, value : T value

Constructor methods inherited from struct Result(T)

new new

Class methods inherited from struct Result(T)

err? : Bool err?, ok? : Bool ok?

Constructor Detail

def self.[](value) : Ok #

Syntax sugar for Ok.done(value).

Ok["hello"] # => same as Ok.done("hello")

def self.created(value) : Ok #

Creates a new Ok instance with the status :created. This method is a shortcut for Ok.new :created, value.

res = Ok.created(value)
res.status # => :created

pp res.unwrap
# or
pp res.value

def self.destroyed(value) : Ok #

Creates a new Ok instance with the status :destroyed. This method is a shortcut for Ok.new :destroyed, value.

res = Ok.destroyed(value)
res.status # => :destroyed

pp res.unwrap
# or
pp res.value

def self.done(value) : Ok #

Creates a new Ok instance with the status :done. This method is a shortcut for Ok.new :done, value.

res = Ok.done(value)
res.status # => :done

pp res.unwrap
# or
pp res.value

def self.new(status : Symbol, value : T) #

Creates a new Ok instance with a custom #status.


def self.new(value : T) #

def self.pending(value) : Ok #

Creates a new Ok instance with the status :pending. This method is a shortcut for Ok.new :pending, value.

res = Ok.pending(value)
res.status # => :pending

pp res.unwrap
# or
pp res.value

def self.updated(value) : Ok #

Creates a new Ok instance with the status :updated. This method is a shortcut for Ok.new :updated, value.

res = Ok.updated(value)
res.status # => :updated

pp res.unwrap
# or
pp res.value

Class Method Detail

def self.type : Symbol #

Result type as a Symbol.

Ok.type # => :ok

Instance Method Detail

def status : Symbol #
Description copied from struct Result(T)

Result status as a Symbol (:done or :fail, etc).


def type : Symbol #

Result type as a Symbol.

res.type # => :ok

def unwrap #

Unwrap the result #value (like Result::unwrap in Rust).


def value : T #

Returns the result value.