aboutsummaryrefslogtreecommitdiffstats
path: root/library/go/slices/reverse.go
blob: a436617b67f944446d245c2fb0693883f71e1156 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package slices

// Reverse reverses given slice.
// It will alter original non-empty slice, consider copy it beforehand.
func Reverse[E any](s []E) []E {
	if len(s) < 2 {
		return s
	}
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s
}

// ReverseStrings reverses given string slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseStrings = Reverse[string]

// ReverseInts reverses given int slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseInts = Reverse[int]

// ReverseInt8s reverses given int8 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseInt8s = Reverse[int8]

// ReverseInt16s reverses given int16 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseInt16s = Reverse[int16]

// ReverseInt32s reverses given int32 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseInt32s = Reverse[int32]

// ReverseInt64s reverses given int64 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseInt64s = Reverse[int64]

// ReverseUints reverses given uint slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseUints = Reverse[uint]

// ReverseUint8s reverses given uint8 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseUint8s = Reverse[uint8]

// ReverseUint16s reverses given uint16 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseUint16s = Reverse[uint16]

// ReverseUint32s reverses given uint32 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseUint32s = Reverse[uint32]

// ReverseUint64s reverses given uint64 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseUint64s = Reverse[uint64]

// ReverseFloat32s reverses given float32 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseFloat32s = Reverse[float32]

// ReverseFloat64s reverses given float64 slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseFloat64s = Reverse[float64]

// ReverseBools reverses given bool slice.
// It will alter original non-empty slice, consider copy it beforehand.
// Deprecated: use Reverse instead.
var ReverseBools = Reverse[bool]