Class: RDF::N3::Algebra::Math::Product

Inherits:
ListOperator
  • Object
show all
Defined in:
lib/rdf/n3/algebra/math/product.rb

Overview

The subject is a list of numbers. The object is calculated as the arithmentic product of those numbers.

Constant Summary collapse

NAME =
:mathProduct
URI =
RDF::N3::Math.product

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ListOperator

#as_literal, #execute, #input_operand, #validate

Methods included from Builtin

#each, #evaluate, #hash, #input_operand, #rank, #to_uri

Instance Method Details

#resolve(list) ⇒ RDF::Term

The math:product operator takes a list of strings or numbers and calculates their sum.

Parameters:

Returns:

See Also:

  • ListOperator#evaluate


16
17
18
# File 'lib/rdf/n3/algebra/math/product.rb', line 16

def resolve(list)
  list.to_a.map(&:as_number).reduce(&:*) || RDF::Literal(1)  # Empty list product is 1
end