@@ -18,15 +18,15 @@ go install github.com/logic-building/functional-go/gofp
1818```
1919
2020### dep Gopkg.toml entry
21- ```
21+ ``` toml
2222[[constraint ]]
2323name = " github.com/logic-building/functional-go"
2424version = " 8.13.1"
2525```
2626
2727### Quick Start
2828#### For Data types available in golang
29- ```
29+ ``` go
3030import " github.com/logic-building/functional-go/fp"
3131
3232fp.MapInt (square, []int {1 , 2 , 3 , 4 }) // Returns: [1 4 9 16]
@@ -39,7 +39,7 @@ func square(num int) int {
3939#### Four variants of function. 1 is given above and 3 are given below
4040##### MapInt, MapIntPtr, MapIntErr, MapIntPtrErr
4141### MapIntPtr
42- ```
42+ ``` go
4343package main
4444
4545import (
@@ -69,7 +69,7 @@ output:
6969```
7070
7171### MapIntErr
72- ```
72+ ``` go
7373package main
7474
7575import (
@@ -98,7 +98,7 @@ output:
9898```
9999
100100### MapIntPtrErr
101- ```
101+ ``` go
102102package main
103103
104104import (
@@ -138,19 +138,19 @@ Design 2: All functional code in one place
138138```
139139### Design 1: Functional code distributed within different package
140140#### Generate functional code for struct - Employee
141- ```
141+ ``` go
142142 type Employee struct {
143143 id int
144144 name string
145145 salary float64
146146 }
147147```
148148#### 1. Add line given below in the file where struct resides
149- ```
149+ ``` go
150150// go:generate gofp -destination fp.go -pkg employee -type "Employee"
151151```
152152##### Example:
153- ```
153+ ``` go
154154 // go:generate gofp -destination fp.go -pkg employee -type "Employee"
155155 type Employee struct {
156156 id int
@@ -178,7 +178,7 @@ Design 2: All functional code in one place
178178 go generate ./...
179179```
180180#### You are done. Enjoy the functional code
181- ```
181+ ``` go
182182 emp1 := employee.Employee {1 , " A" , 1000 }
183183 emp2 := employee.Employee {2 , " B" , 1000 }
184184 emp3 := employee.Employee {3 , " C" , 1000 }
@@ -840,7 +840,7 @@ SetStrSync
840840```
841841
842842### Example1 - Map : return the list of the square of each items in the list
843- ```
843+ ``` go
844844squareList := fp.MapInt (squareInt, []int {1 , 2 , 3 }) // see the map_test.go for detail
845845
846846func squareInt (num int ) int {
@@ -855,7 +855,7 @@ output
855855```
856856
857857### Example2 - Filter: filter all the even numbers in the list
858- ```
858+ ``` go
859859filteredList := fp.FilterInt (isEven, []int {1 , 2 , 3 , 4 })
860860
861861func isEven (num int ) bool {
@@ -868,7 +868,7 @@ output:
868868```
869869
870870### Example3 - fp.FilterMap: Multiply all positive numbers in the list by 2
871- ```
871+ ``` go
872872filteredList := FilterMapInt (isPositive, multiplyBy2, []int {-1 , 0 , 2 , 4 })
873873
874874func isPositive (num int ) bool {
@@ -883,7 +883,7 @@ output:
883883```
884884
885885### Example4 - Every: Test if every number in the list is even
886- ```
886+ ``` go
887887list := []bool {true , true , true , true }
888888fp.EveryBool (fp.True , list) // Returns true
889889
@@ -892,25 +892,25 @@ fp.EveryInt(isEven, list1) // Returns true
892892```
893893
894894### Example5 - Exists: Test if number presents in the list
895- ```
895+ ``` go
896896list1 := []int {8 , 2 , 10 , 4 }
897897fp.ExistsInt (8 , list1) // returns true
898898```
899899
900900### Example6 - Max: Get max number in the list
901- ```
901+ ``` go
902902list := []int {8 , 2 , 10 , 4 }
903903max := fp.MaxInt (list) // returns 10
904904```
905905
906906### Example7 - Min: Get min number in the list
907- ```
907+ ``` go
908908list := []int {8 , 2 , 10 , 4 }
909909min := fp.MinInt (list) // returns 2
910910```
911911
912912### Example8 - Returns a new list after dropping the given item
913- ```
913+ ``` go
914914newList := fp.DropInt (1 , []int {1 , 2 , 3 , 1 }) // returns [2, 3]
915915
916916To drop multiple items:
@@ -919,26 +919,26 @@ newList := fp.DropInts([]int{1, 2}, []int{1, 2, 3, 1}) // returns [3]
919919```
920920
921921### Example9 - Distinct: returns distinct list
922- ```
922+ ``` go
923923list := []int {8 , 2 , 8 , 0 , 2 , 0 }
924924distinct := fp.DistinctInt (list) // returns [8, 2, 0]
925925```
926926
927927### Example10 - Set : Create set objects and apply union operation
928- ```
928+ ``` go
929929 mySet1 := set.NewInt ([]int {10 , 20 , 30 , 20 })
930930 mySet2 := set.NewInt ([]int {30 , 40 , 50 })
931931 mySet3 := mySet1.Union (mySet2) // Returns [10, 20, 30, 40, 50]
932932```
933933
934934### Example11 - Range : accepts lower and end int and returns range list
935- ```
935+ ``` go
936936 fp.Range (1 , 5 ) // returns [1, 2, 3, 4]
937937 fp.Range (1 , 5 , 2 ) // returns [1, 3]
938938```
939939
940940### Example12 - Remove :
941- ```
941+ ``` go
942942 NewList := RemoveInt (isEven, []int {1 , 2 , 3 , 4 }) // returns [1, 3]
943943
944944 func isEven (num int ) bool {
@@ -948,7 +948,7 @@ distinct := fp.DistinctInt(list) // returns [8, 2, 0]
948948```
949949
950950### Example13 - DropWhileInt :
951- ```
951+ ``` go
952952 NewList := DropWhile (isEven, []int {4 , 2 , 3 , 4 }) // returns [3, 4]
953953
954954 func isEven (num int ) bool {
@@ -958,7 +958,7 @@ distinct := fp.DistinctInt(list) // returns [8, 2, 0]
958958```
959959
960960### Example14 - TakeWhileInt :
961- ```
961+ ``` go
962962 NewList := TakeWhile (isEven, []int {4 , 2 , 3 , 4 }) // returns [4, 2]
963963
964964 func isEven (num int ) bool {
0 commit comments