-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduce_func.go
77 lines (69 loc) · 3.13 KB
/
reduce_func.go
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
package streams
// Copyright 2022 streams Author. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import (
"strings"
"github.com/go-the-way/streams/reducefunc"
)
var (
reduceString = func(str []string, sep string) string { return strings.Join(str, sep) }
// ReduceString
// []String{1, 2, 3} => "123"
ReduceString = func(str []string) string { return reduceString(str, "") }
// ReduceStringWithComma
// []String{1, 2, 3} => "1,2,3"
ReduceStringWithComma = func(str []string) string { return reduceString(str, ",") }
// ReduceStringWithDot
// []String{1, 2, 3} => "1.2.3"
ReduceStringWithDot = func(str []string) string { return reduceString(str, ".") }
// ReduceStringWithSpace
// []String{1, 2, 3} => "1 2 3"
ReduceStringWithSpace = func(str []string) string { return reduceString(str, " ") }
// ReduceStringWithLine
// []String{1, 2, 3} => "1\n2\n3"
ReduceStringWithLine = func(str []string) string { return reduceString(str, "\n") }
// ReduceInt8
// []int8{1, 2, 3} => 1 + 2 + 3 => 6
ReduceInt8 = func(i []int8) int8 { return Reduce(i, 0, reducefunc.Number[int8]) }
// ReduceInt16
// []int8{1, 2, 3} => 1 + 2 + 3 => 6
ReduceInt16 = func(i []int16) int16 { return Reduce(i, 0, reducefunc.Number[int16]) }
// ReduceInt32
// []int32{1, 2, 3} => 1 + 2 + 3 => 6
ReduceInt32 = func(i []int32) int32 { return Reduce(i, 0, reducefunc.Number[int32]) }
// ReduceInt
// []int{1, 2, 3} => 1 + 2 + 3 => 6
ReduceInt = func(i []int) int { return Reduce(i, 0, reducefunc.Number[int]) }
// ReduceInt64
// []int64{1, 2, 3} => 1 + 2 + 3 => 6
ReduceInt64 = func(i []int64) int64 { return Reduce(i, 0, reducefunc.Number[int64]) }
// ReduceUint8
// []uint8{1, 2, 3} => 1 + 2 + 3 => 6
ReduceUint8 = func(i []uint8) uint8 { return Reduce(i, 0, reducefunc.Number[uint8]) }
// ReduceUint16
// []uint8{1, 2, 3} => 1 + 2 + 3 => 6
ReduceUint16 = func(i []uint16) uint16 { return Reduce(i, 0, reducefunc.Number[uint16]) }
// ReduceUint32
// []uint32{1, 2, 3} => 1 + 2 + 3 => 6
ReduceUint32 = func(i []uint32) uint32 { return Reduce(i, 0, reducefunc.Number[uint32]) }
// ReduceUint
// []uint{1, 2, 3} => 1 + 2 + 3 => 6
ReduceUint = func(i []uint) uint { return Reduce(i, 0, reducefunc.Number[uint]) }
// ReduceUint64
// []uint64{1, 2, 3} => 1 + 2 + 3 => 6
ReduceUint64 = func(i []uint64) uint64 { return Reduce(i, 0, reducefunc.Number[uint64]) }
// ReduceFloat32
// []float32{1, 2, 3} => 1 + 2 + 3 => 6
ReduceFloat32 = func(f []float32) float32 { return Reduce(f, 0, reducefunc.Number[float32]) }
// ReduceFloat64
// []float64{1, 2, 3} => 1 + 2 + 3 => 6
ReduceFloat64 = func(f []float64) float64 { return Reduce(f, 0, reducefunc.Number[float64]) }
)