@@ -31,11 +31,13 @@ func ExampleLoader() {
31
31
panic (err )
32
32
}
33
33
34
- mappedLoader := dataloadgen .NewLoader (func (ctx context.Context , keys []string ) (ret []int , errs []error ) {
34
+ mappedLoader := dataloadgen .NewMappedLoader (func (ctx context.Context , keys []string ) (ret map [string ]int , errs map [string ]error ) {
35
+ ret = make (map [string ]int , len (keys ))
36
+ errs = make (map [string ]error , len (keys ))
35
37
for _ , key := range keys {
36
38
num , err := strconv .ParseInt (key , 10 , 32 )
37
- ret = append ( ret , int (num ) )
38
- errs = append ( errs , err )
39
+ ret [ key ] = int (num )
40
+ errs [ key ] = err
39
41
}
40
42
return
41
43
},
@@ -143,11 +145,11 @@ func TestPanic(t *testing.T) {
143
145
144
146
func TestMappedLoader (t * testing.T ) {
145
147
ctx := context .Background ()
146
- dl := dataloadgen .NewMappedLoader (func (_ context.Context , keys []string ) (map [string ]* string , map [string ]error ) {
148
+ dl := dataloadgen .NewMappedLoader (func (_ context.Context , keys []string ) (res map [string ]* string , errs map [string ]error ) {
147
149
one := "1"
148
- results : = map [string ]* string {"1" : & one }
149
- errs : = map [string ]error {"3" : errors .New ("not found error" )}
150
- return results , errs
150
+ res = map [string ]* string {"1" : & one }
151
+ errs = map [string ]error {"3" : errors .New ("not found error" )}
152
+ return res , errs
151
153
})
152
154
153
155
thunkOne := dl .LoadThunk (ctx , "1" )
0 commit comments