Module: Oscillo::Combine

Defined in:
lib/oscillo/combine.rb

Overview

Constructs new signals by combining multiple signals together in different ways.

Class Method Summary collapse

Class Method Details

.either(*signals) ⇒ Signal

When any of the signals change, update the new signal with the value of the last changed signal.

Parameters:

  • signals ([Signal])

    the signals to update on

Returns:



10
11
12
13
14
# File 'lib/oscillo/combine.rb', line 10

def self.either(*signals)
  Signal.new(*signals) do |*vs, s|
    s.source.val
  end
end

.when(*signals) {|value| ... } ⇒ Signal

Updates the signal when any of the given signals change and the block evaluates to true. The value is the value of the last changed signal.

Parameters:

  • signals ([Signal])

    the signals to update on

Yields:

  • (value)

    the new value of the last changed signal

Returns:

See Also:



23
24
25
26
27
28
# File 'lib/oscillo/combine.rb', line 23

def self.when(*signals, &block)
  Signal.new(*signals) do |*vs, s|
    s.abort unless block.(s.source.val)
    s.source.val
  end
end

.when_not(*signals) {|value| ... } ⇒ Signal

Updates the signal when any of the given signals change and the block evaluates to false. The value is the value of the last changed signal.

Parameters:

  • signals ([Signal])

    the signals to update on

Yields:

  • (value)

    the new value of the last changed signal

Returns:

See Also:



37
38
39
40
41
42
# File 'lib/oscillo/combine.rb', line 37

def self.when_not(*signals, &block)
  Signal.new(*signals) do |*vs, s|
    s.abort if block.(s.source.val)
    s.source.val
  end
end