Module: RFunk

Defined in:
lib/rfunk/lazy.rb,
lib/rfunk/tuple.rb,
lib/rfunk/version.rb,
lib/rfunk/maybe/none.rb,
lib/rfunk/maybe/some.rb,
lib/rfunk/maybe/option.rb,
lib/rfunk/either/either.rb,
lib/rfunk/either/failure.rb,
lib/rfunk/either/success.rb,
lib/rfunk/attribute/function.rb,
lib/rfunk/attribute/attribute.rb,
lib/rfunk/attribute/immutable.rb,
lib/rfunk/attribute/attribute_type.rb,
lib/rfunk/attribute/error_checking.rb,
lib/rfunk/attribute/assertion_error.rb,
lib/rfunk/attribute/immutable_error.rb,
lib/rfunk/attribute/not_found_error.rb,
lib/rfunk/attribute/type_annotation.rb,
lib/rfunk/attribute/attribute_function.rb,
lib/rfunk/attribute/attribute_variable.rb,
lib/rfunk/attribute/pre_condition_error.rb,
lib/rfunk/attribute/attribute_definition.rb,
lib/rfunk/attribute/post_condition_error.rb

Defined Under Namespace

Modules: Attribute, AttributeDefinition, AttributeFunction Classes: AssertionError, AttributeType, AttributeVariable, Either, ErrorChecking, Failure, Function, Immutable, ImmutableError, Lazy, None, NotFoundError, Option, PostConditionError, PreConditionError, Some, Success, Tuple, TypeAnnotation

Constant Summary collapse

VERSION =
'1.6.1'.freeze

Class Method Summary collapse

Class Method Details

.either(value) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rfunk/either/either.rb', line 26

def either(value)
  if lambda?(value)
    either_with_lambda(value)
  else
    either_with_value(value)
  end
end

.failure(value) ⇒ Object



17
18
19
# File 'lib/rfunk/either/failure.rb', line 17

def failure(value)
  RFunk::Failure.new(value)
end

.lazy(lambda) ⇒ Object



25
26
27
# File 'lib/rfunk/lazy.rb', line 25

def lazy(lambda)
  RFunk::Lazy.new(lambda)
end

.none(value = nil) ⇒ Object



45
46
47
# File 'lib/rfunk/maybe/none.rb', line 45

def none(value = nil)
  RFunk.option(value)
end

.option(value) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/rfunk/maybe/option.rb', line 13

def option(value)
  if [RFunk::Some, RFunk::None].map { |t| value.is_a?(t) }.any?
    value
  elsif nothing?(value)
    RFunk::None.instance
  else
    RFunk::Some.new(value)
  end
end

.some(value) ⇒ Object



57
58
59
# File 'lib/rfunk/maybe/some.rb', line 57

def some(value)
  RFunk.option(value)
end

.success(value) ⇒ Object



17
18
19
# File 'lib/rfunk/either/success.rb', line 17

def success(value)
  RFunk::Success.new(value)
end

.tuple(*values) ⇒ Object



24
25
26
# File 'lib/rfunk/tuple.rb', line 24

def tuple(*values)
  RFunk::Tuple.new(values)
end