struct Spectator::LazyWrapper

Overview

Lazily stores a value of any type. Combines Lazy and Wrapper.

Contains no value until the first call to #get is made. Any type can be stored in this wrapper. However, the type must always be known when retrieving it via #get. The type is inferred from the block, and all blocks must return the same type. Because of this, it is recommended to only have #get called in one location.

This type is expected to be used like so:

@wrapper : LazyWrapper

# ...

def lazy_load
  @wrapper.get { some_expensive_operation }
end

Defined in:

spectator/lazy_wrapper.cr

Constructors

Instance Method Summary

Instance methods inherited from class Object

should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should
, should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_eventually, should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_never, should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def get(& : -> T) : T forall T #

Retrieves the value, if it was previously fetched. On the first invocation of this method, it will yield. The block should return the value to store. Subsequent calls will return the same value and not yield.


[View source]
def initialize #

[View source]