Class: RDF::N3::Algebra::Math::Sum
- Inherits:
-
ListOperator
- Object
- SPARQL::Algebra::Operator::Binary
- ListOperator
- RDF::N3::Algebra::Math::Sum
- Defined in:
- lib/rdf/n3/algebra/math/sum.rb
Overview
schema:
($a_1 .. $a_n) math:sum $a_s
summary: performs addition of numbers
definition:
true if and only if the arithmetic sum of $a_1, .. $a_n equals $a_s.
Requires either:
- all
$a_1, .., $a_nto be bound; or - all but one
$a_i(subject list) to be bound, and$a_sto be bound.
literal domains:
$a_1 .. $a_n:xs:decimal(or its derived types),xs:float, orxs:double(see note on type promotion, and casting from string)$a_s:xs:decimal(or its derived types),xs:float, orxs:double(see note on type promotion, and casting from string)
Constant Summary collapse
- NAME =
:mathSum- URI =
RDF::N3::Math[:sum]
Instance Attribute Summary
Attributes included from Enumerable
Instance Method Summary collapse
-
#resolve(list) ⇒ RDF::Term
Evaluates to the sum of the list elements.
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
Evaluates to the sum of the list elements
36 37 38 |
# File 'lib/rdf/n3/algebra/math/sum.rb', line 36 def resolve(list) list.to_a.map(&:as_number).reduce(&:+) || RDF::Literal(0) # Empty list sums to 0 end |