Sha256: 111568105abdc749cae4730b98b0b6d42cca500c22ee1a01da45628bc24b7ad6

Contents?: true

Size: 402 Bytes

Versions: 2

Compression:

Stored size: 402 Bytes

Contents

require_relative '../function'

Dentaku::AST::Function.register(:sum, :numeric, ->(*args) {
  flatten_args = args.flatten
  if flatten_args.empty?
    raise Dentaku::ArgumentError.for(
        :too_few_arguments,
        function_name: 'SUM()', at_least: 1, given: 0
    ), 'SUM() requires at least one argument'
  end

  flatten_args.map { |arg| Dentaku::AST::Function.numeric(arg) }.reduce(0, :+)
})

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dentaku-3.4.1 lib/dentaku/ast/functions/sum.rb
dentaku-3.4.0 lib/dentaku/ast/functions/sum.rb