@@ -102,7 +102,8 @@ Supported helpers for slices:
102102- [ Repeat] ( #repeat )
103103- [ RepeatBy] ( #repeatby )
104104- [ KeyBy] ( #keyby )
105- - [ Associate / SliceToMap] ( #associate-alias-slicetomap )
105+ - [ SliceToMap / Associate] ( #slicetomap-alias-associate )
106+ - [ FilterSliceToMap] ( #filterslicetomap )
106107- [ Keyify] ( #keyify )
107108- [ Drop] ( #drop )
108109- [ DropRight] ( #dropright )
@@ -299,6 +300,9 @@ Concurrency helpers:
299300- [ Debounce] ( #debounce )
300301- [ DebounceBy] ( #debounceby )
301302- [ Throttle] ( #throttle )
303+ - [ ThrottleWithCount] ( #throttle )
304+ - [ ThrottleBy] ( #throttle )
305+ - [ ThrottleByWithCount] ( #throttle )
302306- [ Synchronize] ( #synchronize )
303307- [ Async] ( #async )
304308- [ Transaction] ( #transaction )
@@ -756,7 +760,7 @@ result := lo.KeyBy(characters, func(char Character) string {
756760
757761[[ play] ( https://go.dev/play/p/mdaClUAT-zZ )]
758762
759- ### Associate (alias: SliceToMap )
763+ ### SliceToMap (alias: Associate )
760764
761765Returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
762766If any of two pairs would have the same key the last one gets added to the map.
@@ -766,14 +770,34 @@ The order of keys in returned map is not specified and is not guaranteed to be t
766770``` go
767771in := []*foo{{baz: " apple" , bar: 1 }, {baz: " banana" , bar: 2 }}
768772
769- aMap := lo.Associate (in, func (f *foo) (string , int ) {
773+ aMap := lo.SliceToMap (in, func (f *foo) (string , int ) {
770774 return f.baz , f.bar
771775})
772776// map[string][int]{ "apple":1, "banana":2 }
773777```
774778
775779[[ play] ( https://go.dev/play/p/WHa2CfMO3Lr )]
776780
781+ ### FilterSliceToMap
782+
783+ Returns a map containing key-value pairs provided by transform function applied to elements of the given slice.
784+
785+ If any of two pairs would have the same key the last one gets added to the map.
786+
787+ The order of keys in returned map is not specified and is not guaranteed to be the same from the original array.
788+
789+ The third return value of the transform function is a boolean that indicates whether the key-value pair should be included in the map.
790+
791+
792+ ``` go
793+ list := []string {" a" , " aa" , " aaa" }
794+
795+ result := lo.FilterSliceToMap (list, func (str string ) (string , int , bool ) {
796+ return str, len (str), len (str) > 1
797+ })
798+ // map[string][int]{"aa":2 "aaa":3}
799+ ```
800+
777801### Keyify
778802
779803Returns a map with each unique element of the slice as a key.
0 commit comments