module Functional
Erlang, Clojure, and Go inspired functional programming tools to Ruby.
Constants
- FinalityError
An exception raised when an attempt is made to modify an immutable object or attribute.
- Infinity
- NaN
Not a number
- ProtocolError
An exception indicating a problem during protocol processing.
- VERSION
The current gem version.
Public Class Methods
Specify a new protocol or retrieve the specification of an existing protocol.
When called without a block the global protocol registry will be searched for a protocol with the matching name. If found the corresponding {Functional::ProtocolInfo} object will be returned. If not found ‘nil` will be returned.
When called with a block, a new protocol with the given name will be created and the block will be processed to provide the specifiction. When successful the new {Functional::ProtocolInfo} object will be returned. An exception will be raised if a protocol with the same name already exists.
@example
Functional::SpecifyProtocol(:Queue) do instance_method :push, 1 instance_method :pop, 0 instance_method :length, 0 end
@param [Symbol] name The global name of the new protocol @yield The protocol definition @return [Functional::ProtocolInfo] the newly created or already existing
protocol specification
@raise [Functional::ProtocolError] when attempting to specify a protocol
that has already been specified.
@see Functional::Protocol
# File lib/functional/protocol.rb, line 38 def SpecifyProtocol(name, &block) name = name.to_sym protocol_info = Protocol.class_variable_get(:@@info)[name] return protocol_info unless block_given? if block_given? && protocol_info raise ProtocolError.new(":#{name} has already been defined") end info = ProtocolInfo.new(name, &block) Protocol.class_variable_get(:@@info)[name] = info end
Private Instance Methods
Specify a new protocol or retrieve the specification of an existing protocol.
When called without a block the global protocol registry will be searched for a protocol with the matching name. If found the corresponding {Functional::ProtocolInfo} object will be returned. If not found ‘nil` will be returned.
When called with a block, a new protocol with the given name will be created and the block will be processed to provide the specifiction. When successful the new {Functional::ProtocolInfo} object will be returned. An exception will be raised if a protocol with the same name already exists.
@example
Functional::SpecifyProtocol(:Queue) do instance_method :push, 1 instance_method :pop, 0 instance_method :length, 0 end
@param [Symbol] name The global name of the new protocol @yield The protocol definition @return [Functional::ProtocolInfo] the newly created or already existing
protocol specification
@raise [Functional::ProtocolError] when attempting to specify a protocol
that has already been specified.
@see Functional::Protocol
# File lib/functional/protocol.rb, line 38 def SpecifyProtocol(name, &block) name = name.to_sym protocol_info = Protocol.class_variable_get(:@@info)[name] return protocol_info unless block_given? if block_given? && protocol_info raise ProtocolError.new(":#{name} has already been defined") end info = ProtocolInfo.new(name, &block) Protocol.class_variable_get(:@@info)[name] = info end