Module: Yast::Builtins::List

Defined in:
src/ruby/yast/builtins.rb

Overview

builtins enclosed in List namespace

Class Method Summary collapse

Class Method Details

.reduce(*params, &block) ⇒ Object

Deprecated.

use Array#reduce instead

Reduces a list to a single value.



357
358
359
360
361
362
363
364
365
366
# File 'src/ruby/yast/builtins.rb', line 357

def self.reduce(*params, &block)
  return nil if params.first.nil?
  list = if params.size == 2 # so first is default and second is list
    return nil if params[1].nil?
    [params.first].concat(Yast.deep_copy(params[1]))
  else
    params.first
  end
  Yast.deep_copy(list).reduce(&block)
end

.swap(list, offset1, offset2) ⇒ Object

Note:

Array#reverse should be used for complete array swap

Creates new list with swaped elements at offset i1 and i2.



370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'src/ruby/yast/builtins.rb', line 370

def self.swap(list, offset1, offset2)
  return nil if list.nil? || offset1.nil? || offset2.nil?

  return Yast.deep_copy(list) if offset1 < 0 || offset2 >= list.size || (offset1 > offset2)

  res = []

  res.concat(list[0..offset1 - 1]) if offset1 > 0
  res.concat(list[offset1..offset2].reverse!)
  res.concat(list[offset2 + 1..-1]) if offset2 < list.size - 1

  Yast.deep_copy(res)
end