Sha256: 40228741e077762581d1601b9427dc52a85c04c5f1d0164933e0a72b3d800ec9

Contents?: true

Size: 932 Bytes

Versions: 5

Compression:

Stored size: 932 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Yoga
  # Utilities used with the Yoga module.
  #
  # @api private
  module Utils
  module_function

    # Takes an array of tokens or set/array of tokens and turns it into a
    # single set.
    #
    # @param tokens [<Yoga::Token, ::Set<Yoga::Token>, ::Enumerable>]
    #   The array to flatten into a set.
    # @return [::Set<Yoga::Token>]
    def flatten_into_set(tokens)
      flatten_into_array(tokens).to_set
    end

    # Takes an array of tokens or a set/array of tokens and turns it into a
    # single array.
    #
    # @param tokens [<Yoga::Token>, ::Set<Yoga::Token>, ::Enumerable]
    #   The array to flatten into a set.
    # @return [<Yoga::Token>]
    def flatten_into_array(tokens)
      tokens.flat_map do |part|
        if part.is_a?(::Enumerable)
          flatten_into_array(part)
        else
          part
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yoga-0.4.1 lib/yoga/utils.rb
yoga-0.3.2 lib/yoga/utils.rb
yoga-0.3.0 lib/yoga/utils.rb
yoga-0.2.1 lib/yoga/utils.rb
yoga-0.2.0 lib/yoga/utils.rb