// Slice returns a slice of all passed arguments.
481024
func Slice(args ...interface{}) interface{} {
	if len(args) == 0 {
		return args
	}

	first := args[0]
	firstType := reflect.TypeOf(first)

	if firstType == nil {
		return args
	}

	if g, ok := first.(Slicer); ok {
		v, err := g.Slice(args)
		if err == nil {
			return v
		}

		// If Slice fails, the items are not of the same type and
		// []interface{} is the best we can do.
		return args
	}

	if len(args) > 1 {
		// This can be a mix of types.
		for i := 1; i < len(args); i++ {
			if firstType != reflect.TypeOf(args[i]) {
				// []interface{} is the best we can do
				return args
			}
		}
	}

	slice := reflect.MakeSlice(reflect.SliceOf(firstType), len(args), len(args))
	for i, arg := range args {
		slice.Index(i).Set(reflect.ValueOf(arg))
	}
	return slice.Interface()
}
1072542
func (c *concat) slice(start, end int64) node {
	// If only slicing into one side, recurse to that side.
	if end <= c.Split {
		return c.Left.slice(start, end)
	}
	if start >= c.Split {
		return c.Right.slice(start-c.Split, end-c.Split)
	}
	clength := c.Split + c.rLength()
	if start <= 0 && end >= clength {
		return c
	}

	Left := c.Left
	LeftLen := c.Split
	if start > 0 || end < c.Split {
		Left = Left.slice(start, end)
		LeftLen = -1 // Recompute if needed.
	}

	Right := c.Right
	RightLen := int64(c.RLen)
	if start > c.Split || end < clength {
		Right = c.Right.slice(start-c.Split, end-c.Split)
		RightLen = -1 // Recompute if needed.
	}

	return conc(Left, Right, LeftLen, RightLen)
}
681741
func (fc *Flow) Slices(slices [][]interface{}) (ret *Dataset) {

	ret = fc.NewNextDataset(1)
	step := fc.AddOneToOneStep(nil, ret)
	step.IsOnDriverSide = true
	step.Name = "Slices"
	step.Function = func(readers []io.Reader, writers []io.Writer, stat *pb.InstructionStat) error {
		for _, slice := range slices {
			stat.InputCounter++
			err := util.NewRow(util.Now(), slice).WriteTo(writers[0])
			if err != nil {
				return err
			}
			stat.OutputCounter++
		}
		return nil
	}
	return

}
625457
func (ns *Namespace) SliceString(a interface{}, startEnd ...interface{}) (string, error) {
	aStr, err := cast.ToStringE(a)
	if err != nil {
		return "", err
	}

	var argStart, argEnd int

	argNum := len(startEnd)

	if argNum > 0 {
		if argStart, err = cast.ToIntE(startEnd[0]); err != nil {
			return "", errors.New("start argument must be integer")
		}
	}
	if argNum > 1 {
		if argEnd, err = cast.ToIntE(startEnd[1]); err != nil {
			return "", errors.New("end argument must be integer")
		}
	}

	if argNum > 2 {
		return "", errors.New("too many arguments")
	}

	asRunes := []rune(aStr)

	if argNum > 0 && (argStart < 0 || argStart >= len(asRunes)) {
		return "", errors.New("slice bounds out of range")
	}

	if argNum == 2 {
		if argEnd < 0 || argEnd > len(asRunes) {
			return "", errors.New("slice bounds out of range")
		}
		return string(asRunes[argStart:argEnd]), nil
	} else if argNum == 1 {
		return string(asRunes[argStart:]), nil
	} else {
		return string(asRunes[:]), nil
	}

}
39089
func Slice(slice interface{}, less func(i, j int) bool) {
	Sort(SliceSorter(slice, less))
}
1166932
func Merge(slices ...Slice) (Slice, error) {
	// Calculate overall length
	l := ValueLength(0)
	for _, s := range slices {
		if err := s.AssertType(Object); err != nil {
			return nil, WithStack(err)
		}
		byteSize, err := s.ByteSize()
		if err != nil {
			return nil, WithStack(err)
		}
		l += byteSize
	}

	if len(slices) == 1 {
		// Fast path, only 1 slice
		return slices[0], nil
	}

	// Create a buffer to hold all slices.
	b := NewBuilder(uint(l))
	keys := make(map[string]struct{})
	if err := b.OpenObject(); err != nil {
		return nil, WithStack(err)
	}
	for _, s := range slices {
		it, err := NewObjectIterator(s, true)
		if err != nil {
			return nil, WithStack(err)
		}
		for it.IsValid() {
			keySlice, err := it.Key(true)
			if err != nil {
				return nil, WithStack(err)
			}
			key, err := keySlice.GetString()
			if err != nil {
				return nil, WithStack(err)
			}
			if _, found := keys[key]; !found {
				// Record key
				keys[key] = struct{}{}

				// Fetch value
				value, err := it.Value()
				if err != nil {
					return nil, WithStack(err)
				}

				// Add key,value
				if err := b.addInternalKeyValue(key, NewSliceValue(value)); err != nil {
					return nil, WithStack(err)
				}
			}

			// Move to next field
			if err := it.Next(); err != nil {
				return nil, WithStack(err)
			}
		}
	}
	if err := b.Close(); err != nil {
		return nil, WithStack(err)
	}

	// Return slice
	result, err := b.Slice()
	if err != nil {
		return nil, WithStack(err)
	}
	return result, nil
}
1241838
func stringSlice(sliceLike interface{}) []string {
	var strSlice []string
	switch sl := sliceLike.(type) {
	case string:
		if len(sl) > 0 {
			parts, err := shlex.Split(expandEnv(sl))
			if err != nil {
				printErrorf("Error when parsing cmd `%v`: %v. Proceeding with %q.", sl, err, parts)
			}
			strSlice = append(strSlice, parts...)
		}
	case []interface{}:
		parts := make([]string, len(sl))
		for i, v := range sl {
			parts[i] = expandEnv(fmt.Sprintf("%v", v))
		}
		strSlice = append(strSlice, parts...)
	default:
		panic(StatusError{fmt.Errorf("unknown type: %v", sl), 65})
	}
	return strSlice
}
116854
func (c *Command) Args() []*Arg {
	ret := make([]*Arg, len(c.args))
	copy(ret, c.args)

	return ret
}
1126853
func (p *ListParam) Args() []string {
	if len(p.values) == 0 {
		return []string{}
	}
	out := make([]string, 0, len(p.values))
	for _, v := range p.values {
		out = append(out, v.Args()...)
	}
	return out
}
1338921
func (s *Shuffler) Slice(slice Interface) {
	rv := reflect.ValueOf(slice)
	swap := reflect.Swapper(slice)
	(*rand.Rand)(s).Shuffle(rv.Len(), swap)
}
944124
func sliceParser(rd *proto.Reader, n int64) (interface{}, error) {
	vals := make([]interface{}, 0, n)
	for i := int64(0); i < n; i++ {
		v, err := rd.ReadReply(sliceParser)
		if err != nil {
			if err == Nil {
				vals = append(vals, nil)
				continue
			}
			if err, ok := err.(proto.RedisError); ok {
				vals = append(vals, err)
				continue
			}
			return nil, err
		}

		switch v := v.(type) {
		case string:
			vals = append(vals, v)
		default:
			vals = append(vals, v)
		}
	}
	return vals, nil
}
601286
func InterfaceSlice(slice interface{}) []interface{} {
	s := reflect.ValueOf(slice)
	if s.Kind() != reflect.Slice {
		panic("InterfaceSlice() given a non-slice type")
	}

	ret := make([]interface{}, s.Len())

	for i := 0; i < s.Len(); i++ {
		ret[i] = s.Index(i).Interface()
	}

	return ret
}
588199
func (b *Bitset) Slice(startingBit, size int) Bitset {
	ret := Bitset{}
	ret.Create(size)
	ret.bits = b.bits[startingBit : startingBit+size]
	return ret
}
925309
func (v *Value) Slice(i, j int) *Value {
	switch v.getResolvedValue().Kind() {
	case reflect.Array, reflect.Slice:
		return AsValue(v.getResolvedValue().Slice(i, j).Interface())
	case reflect.String:
		runes := []rune(v.getResolvedValue().String())
		return AsValue(string(runes[i:j]))
	default:
		logf("Value.Slice() not available for type: %s\n", v.getResolvedValue().Kind().String())
		return AsValue([]int{})
	}
}
1373550
func (b *buffer) Slice(off, n int) ([]byte, error) {
	end := off + n
	if err := b.fill(end); err != nil {
		return nil, err
	}
	return b.buf[off:end], nil
}
806107
func (p *Param) SliceTmpVarCode() string {
	const code = `var %s *%s
	if len(%s) > 0 {
		%s = &%s[0]
	}`
	tmp := p.tmpVar()
	return fmt.Sprintf(code, tmp, p.Type[2:], p.Name, tmp, p.Name)
}
270600
func StringSlice(val, sep string) ([]string, error) {
	return strings.Split(val, sep), nil
}