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?, initialize initialize, 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")

[View source]
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

[View source]
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

[View source]
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

[View source]
def self.new(status : Symbol, value : T) #

Creates a new Ok instance with a custom #status.


[View source]
def self.new(value : T) #

[View source]
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

[View source]
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

[View source]

Class Method Detail

def self.type : Symbol #

Result type as a Symbol.

Ok.type # => :ok

[View source]

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

[View source]
def unwrap #

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


[View source]
def value : T #

Returns the result value.


[View source]