view modules/stdlib/lib/puppet/parser/functions/intersection.rb @ 482:d83de9b3a62b default tip

Update hiera.yaml within Puppet config Forgot that we manage it from here. Now has content to match new packages
author IBBoard <dev@ibboard.co.uk>
date Fri, 30 Aug 2024 16:10:36 +0100
parents adf6fe9bbc17
children
line wrap: on
line source

# frozen_string_literal: true

#
# intersection.rb
#
module Puppet::Parser::Functions
  newfunction(:intersection, type: :rvalue, doc: <<-DOC
    @summary
      This function returns an array of the intersection of two.

    @return
      an array of the intersection of two.

    @example Example Usage:
      intersection(["a","b","c"],["b","c","d"])  # returns ["b","c"]
      intersection(["a","b","c"],[1,2,3,4])      # returns [] (true, when evaluated as a Boolean)
  DOC
  ) do |arguments|
    # Two arguments are required
    raise(Puppet::ParseError, "intersection(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2

    first = arguments[0]
    second = arguments[1]

    raise(Puppet::ParseError, "intersection(): Requires 2 arrays, got #{first.class} and #{second.class}") unless first.is_a?(Array) && second.is_a?(Array)

    result = first & second

    return result
  end
end

# vim: set ts=2 sw=2 et :