logic-building/functional-go
This library is inspired by functional programming - Clojure
fix issues with higher versioning number
add go mod file with new version series ver1.0.0 to fix go mod issue with some internal file use with higher version.
Method chain functionality for Basic type as well as struct - Map, Filter, Sort, Distinct, Reverse, DropWhile, TakeWhile, Remove Example: ```go // Use MakeIntSlicePtr for pointer version r := fp.MakeIntSlice([]int{3, 2, 1}...). Filter(odd). Map(square). Sort() fmt.Println(r) // [1 9] func odd (num int) bool { return num % 2 != 0 } func square(num int) int { return num * num } ```
Eg: PMapInt(squareInt, []int{v1, v2, v3}, Optional{FixedPool: 2, RandomOrder: true}) The default behavior of PMap: a. number of Goroutines == length of the list. b. Order is guaranteed
New functions for struct - (Distinct, Intersection, Union, Difference, Superset, Subset, Set) compares each member of a struct with another struct in the list.
New functions to compare slice and map. Equal<Type>sP : eg EqualIntsP, EqualFloats64P EqualMap<Type1><Type2>: eg. EqualMapIntP , EqualMapInt64Float64P New function to check if the slice is distinct Distinct<Type>P: eg. DistinctIntP Auto-generate code for struct has options to include the only list - //go:generate gofp -destination fp.go -pkg employee -type "Employee" -only "Distinct, DistinctPtr, DistinctP" A full list of value for option `only` is provided in README
Added function - Dedupe<Type> Auto-generated code for sorting for struct takes pointer types.
Auto-generated code for struct has set and sort related functions as default. Options -set or -sort will override the default behavior of auto-generation of functions related to set & sort. Added new predicate functions: a. Zero<Type>P b. Neg<Type>P c. Pos<Type>P d. Even<Type>P e. Odd<Type>P
Auto-generated code for struct has set and sort related functions as default. Options -set or -sort will override the default behavior of auto-generation of functions related to set & sort. Added new predicate functions: a. Zero<Type>P b. Neg<Type>P c. Pos<Type>P d. Even<Type>P e. Odd<Type>P
1. Added standard set functions: Union, Intersection, Difference, Set, Superset, Subset. 2. Added option -set to generate set functions- Union, Intersection, Difference, Set, Superset, Subset for struct. eg. //go:generate gofp -destination fp.go -pkg employee -type "Employee" -set "Employee:Name:string" New Generated Functions will be 1. SetEmployeeByName 2. UnionEmployeeBytName 3. IntersectionEmployeeByName 4. DifferenceEmployeeByName 5. SupersetEmployeeByName 6. SubsetEmployeeByName
Auto-generated code has a new option to generate sorting methods for struct: --------------------------------------- -sort "Employee:Name, Employee:Salary" eg: //go:generate gofp -destination fp.go -pkg employee -type "Employee" -sort "Employee:Name" type Employee struct { Id int Name string Salary float64 } Generated sorting functions: 1. SortEmployeeByName 2. SortEmployeeByNameDesc 3. SortEmployeeByNamePtr 4. SortEmployeeByNameDescPtr New Standard functions: ------------------------- Reverse<TYPE>: To reverse list Ex. ReverseInt Keys<Type>: return keys of the map Take<Type>: return n items from the list
This new function takes a different type of input and returns a different type of output. Eg. r, err := PMapStrIntErr(fun1, []string{"ram", "jesus"}) func fun1(v string) (int, error) { // some logic return 0, nil } Auto-generated code for user-defined type has this functionality too. Eg. r, err := PMapStrEmployeeErr(fun1, []string{"ram", "jesus"})
Added new functionality for PMap to support error handling.
Now there are four variants of functions: 1. MapInt: Returns new List (Old) 2. MapIntPtr: Returns new list with a pointer type (Old) 3. MapIntErr : Returns new list and error (New) 4. MapIntPtrErr: Returns new list with pointer type and error(New) All four variants are supported in the following functions: Map Filter FilterMap DropWhile Every Remove Reduce Some TakeWhile
Added function to support pointer for the user-defined data type in auto-generate code. "Ptr" is appended in each new function. Available functions: Map -> MapInt, MapStrInt, MapIntPtr ... Filter -> FilterInt, FilterStrInt, FilterIntPtr ... FilterMap -> FilterMapInt, FilterMapIntStr, FilterMapIntPtr ... PMap -> PMapInt, PMapIntStr, PMapInt, PMapIntPtr ... Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Merge Zip Auto-generated functions for the user-defined data type for a different combination of input and output Map, MapPtr Filter, FilterPtr FilterMap, FilterMapPtr PMap, PMapPtr Reduce, ReducePtr Remove, RemovePtr Some, SomePtr TakeWhile, TakeWhilePtr DropWhile, DropWhilePtr Every, EveryPtr Rest, RestPtr Merge, MergePtr Zip, ZipPtr
Added function to support pointer data type. Added Ptr at end of each function to call pointer data type. MapIntPtr... FilterMapPtr... . . . Available functions: Map -> MapInt, MapStrInt, MapIntPtr ... Filter -> FilterInt, FilterStrInt, FilterIntPtr ... FilterMap -> FilterMapInt, FilterMapIntStr, FilterMapIntPtr ... PMap -> PMapInt, PMapIntStr, PMapInt, PMapIntPtr ... Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Merge Zip Auto-generated functions for the user-defined data type for a different combination of input and output Map Filter, FilterPtr FilterMap Pmap Reduce Remove Some TakeWhile DropWhile Every Rest Merge Zip
Merge - Merges 2 maps and returns a new map Zip - Zip two lists and return a new map Available functions: Map -> MapInt, MapStrInt ... Filter -> FilterInt, FilterStrInt ... FilterMap -> FilterMapInt, FilterMapIntStr ... PMap -> PMapInt, PMapIntStr ... Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Merge Zip Auto generated functions for user defined data type for different combination of input and output Map Filter FilterMap Pmap Reduce Remove Some TakeWhile DropWhile Every Rest Merge Zip
Map -> MapInt, MapStrInt ... Filter -> FilterInt, FilterStrInt ... FilterMap -> FilterMapInt, FilterMapIntStr ... PMap -> PMapInt, PMapIntStr ... Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Auto generated functions for user defined data type for different combination of input and output Map Filter FilterMap Pmap Reduce Remove Some TakeWhile DropWhile Every Rest
Map -> MapInt, MapStrInt ... Filter -> FilterInt, FilterStrInt ... FilterMap -> FilterMapInt, FilterMapIntStr ... PMap -> PMapInt, PMapIntStr ... Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Auto generated functions for user defined data type Map Filter FilterMap Pmap Reduce Remove Some TakeWhile DropWhile Every Rest
Map Filter FilterMap Pmap Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Auto generated functions for user defined data type Map Filter FilterMap Pmap Reduce Remove Some TakeWhile DropWhile Every Rest
Functions available for basic data types: Map Filter FilterMap Pmap Distinct Drop DropWhile Every Max Min MinMax Range Remove Reduce Rest Some TakeWhile Auto generated functions for user defined data type Map Filter FilterMap Pmap Reduce Remove Some TakeWhile DropWhile Every Rest
Functions available for basic data types: 1. Map 2. Filter 3. FilterMap 4. Pmap 5. Distinct 6. Drop 7. DropWhile 8. Every 9. Max 10. Min 11. MinMax 12. Range 13. Remove 14. Reduce 15. Rest 16. Some 17. TakeWhile Auto generated functions for user defined data type 1. Map 2. Filter 3. FilterMap 4. Pmap 5. Reduce 6. Remove 7. Some 8. TakeWhile 9. DropWhile 10. Every 11. Rest
Added function: Exists. Functions included in autogenerated code for user defined type - 1. Map 2. Filter 3. Some 4. Remove
