Skip to content

Commit ac2bbee

Browse files
committed
feat: add go style doc
1 parent 5c2c1e8 commit ac2bbee

10 files changed

+23
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ Pipe2(fp.Filter(isPositive), fp.Map(sumTwo))([]int{1, 2, 3, -1})
223223

224224
#### Curry
225225

226+
Allow to transfrom a function that receives a certain amount of params in single functions that take one single param each.
227+
226228
Variations `Curry2`, `Curry3` and `Curry4` stating the number of params will be curried individually.
227229

228230
```go

compose.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package fp
22

3+
// Performs right-to-left function composition of two functions
34
func Compose2[T1, T2, R any](fn2 func(T2) R, fn1 func(T1) T2) func(T1) R {
45
return func(t1 T1) R {
56
return fn2(fn1(t1))
67
}
78
}
89

10+
// Performs right-to-left function composition of three functions
911
func Compose3[T1, T2, T3, R any](fn3 func(T3) R, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R {
1012
return func(t1 T1) R {
1113
return fn3(fn2(fn1(t1)))
1214
}
1315
}
1416

17+
// Performs right-to-left function composition of four functions
1518
func Compose4[T1, T2, T3, T4, R any](fn4 func(T4) R, fn3 func(T3) T4, fn2 func(T2) T3, fn1 func(T1) T2) func(T1) R {
1619
return func(t1 T1) R {
1720
return fn4(fn3(fn2(fn1(t1))))

curry.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fp
22

3+
// Allow to transfrom a function that receives two params in single functions that take one single param each
34
func Curry2[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R {
45
return func(t1 T1) func(T2) R {
56
return func(t2 T2) R {
@@ -8,6 +9,7 @@ func Curry2[T1, T2, R any](fn func(T1, T2) R) func(T1) func(T2) R {
89
}
910
}
1011

12+
// Like Curry2 but with three params
1113
func Curry3[T1, T2, T3, R any](fn func(T1, T2, T3) R) func(T1) func(T2) func(T3) R {
1214
return func(t1 T1) func(T2) func(T3) R {
1315
return func(t2 T2) func(T3) R {
@@ -18,6 +20,7 @@ func Curry3[T1, T2, T3, R any](fn func(T1, T2, T3) R) func(T1) func(T2) func(T3)
1820
}
1921
}
2022

23+
// Like Curry2 but with four params
2124
func Curry4[T1, T2, T3, T4, R any](fn func(T1, T2, T3, T4) R) func(T1) func(T2) func(T3) func(T4) R {
2225
return func(t1 T1) func(T2) func(T3) func(T4) R {
2326
return func(t2 T2) func(T3) func(T4) R {

every.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func Every[T any](predicate func(T) bool) func([]T) bool {
1414
}
1515
}
1616

17+
// See Every but callback receives index of element.
1718
func EveryWithIndex[T any](predicate func(T, int) bool) func([]T) bool {
1819
return func(xs []T) bool {
1920

@@ -27,6 +28,7 @@ func EveryWithIndex[T any](predicate func(T, int) bool) func([]T) bool {
2728
}
2829
}
2930

31+
// Like Every but callback receives index of element and the whole array.
3032
func EveryWithSlice[T any](predicate func(T, int, []T) bool) func([]T) bool {
3133
return func(xs []T) bool {
3234

filter.go

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func Filter[T any](predicate func(T) bool) func([]T) []T {
1616
}
1717
}
1818

19+
// See Filter but callback receives index of element.
1920
func FilterWithIndex[T any](predicate func(T, int) bool) func([]T) []T {
2021
return func(xs []T) []T {
2122

@@ -31,6 +32,7 @@ func FilterWithIndex[T any](predicate func(T, int) bool) func([]T) []T {
3132
}
3233
}
3334

35+
// Like Filter but callback receives index of element and the whole array.
3436
func FilterWithSlice[T any](predicate func(T, int, []T) bool) func([]T) []T {
3537
return func(xs []T) []T {
3638

flatMap.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func FlatMap[T any, R any](callback func(T) []R) func([]T) []R {
1414
}
1515
}
1616

17+
// See FlatMap but callback receives index of element.
1718
func FlatMapWithIndex[T any, R any](callback func(T, int) []R) func([]T) []R {
1819
return func(xs []T) []R {
1920

@@ -27,6 +28,7 @@ func FlatMapWithIndex[T any, R any](callback func(T, int) []R) func([]T) []R {
2728
}
2829
}
2930

31+
// Like FlatMap but callback receives index of element and the whole array.
3032
func FlatMapWithSlice[T any, R any](callback func(T, int, []T) []R) func([]T) []R {
3133
return func(xs []T) []R {
3234

map.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func Map[T any, R any](callback func(T) R) func([]T) []R {
1414
}
1515
}
1616

17+
// See Map but callback receives index of element.
1718
func MapWithIndex[T any, R any](callback func(T, int) R) func([]T) []R {
1819
return func(xs []T) []R {
1920

@@ -27,6 +28,7 @@ func MapWithIndex[T any, R any](callback func(T, int) R) func([]T) []R {
2728
}
2829
}
2930

31+
// Like Map but callback receives index of element and the whole array.
3032
func MapWithSlice[T any, R any](callback func(T, int, []T) R) func([]T) []R {
3133
return func(xs []T) []R {
3234

pipe.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package fp
22

3+
// Performs left-to-right function composition of two functions
34
func Pipe2[T1, T2, R any](fn1 func(T1) T2, fn2 func(T2) R) func(T1) R {
45
return func(t1 T1) R {
56
return fn2(fn1(t1))
67
}
78
}
89

10+
// Performs left-to-right function composition of three functions
911
func Pipe3[T1, T2, T3, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) R) func(T1) R {
1012
return func(t1 T1) R {
1113
return fn3(fn2(fn1(t1)))
1214
}
1315
}
1416

17+
// Performs left-to-right function composition of four functions
1518
func Pipe4[T1, T2, T3, T4, R any](fn1 func(T1) T2, fn2 func(T2) T3, fn3 func(T3) T4, fn4 func(T4) R) func(T1) R {
1619
return func(t1 T1) R {
1720
return fn4(fn3(fn2(fn1(t1))))

reduce.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func Reduce[T any, R any](callback func(R, T) R, acc R) func([]T) R {
1212
}
1313
}
1414

15+
// See Reduce but callback receives index of element.
1516
func ReduceWithIndex[T any, R any](callback func(R, T, int) R, acc R) func([]T) R {
1617
return func(xs []T) R {
1718

@@ -23,6 +24,7 @@ func ReduceWithIndex[T any, R any](callback func(R, T, int) R, acc R) func([]T)
2324
}
2425
}
2526

27+
// Like Reduce but callback receives index of element and the whole array.
2628
func ReduceWithSlice[T any, R any](callback func(R, T, int, []T) R, acc R) func([]T) R {
2729
return func(xs []T) R {
2830

some.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func Some[T any](predicate func(T) bool) func([]T) bool {
1414
}
1515
}
1616

17+
// See Some but callback receives index of element.
1718
func SomeWithIndex[T any](predicate func(T, int) bool) func([]T) bool {
1819
return func(xs []T) bool {
1920

@@ -27,6 +28,7 @@ func SomeWithIndex[T any](predicate func(T, int) bool) func([]T) bool {
2728
}
2829
}
2930

31+
// Like Some but callback receives index of element and the whole array.
3032
func SomeWithSlice[T any](predicate func(T, int, []T) bool) func([]T) bool {
3133
return func(xs []T) bool {
3234

0 commit comments

Comments
 (0)