Skip to content

Commit

Permalink
Fix ObjxMapSlice (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
onrik authored and hanzei committed Jan 29, 2018
1 parent ca93b98 commit e89b2c1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions type_specific_codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,21 @@ func (v *Value) MustObjxMap() Map {
// ObjxMapSlice gets the value as a [](Map), returns the optionalDefault
// value or nil if the value is not a [](Map).
func (v *Value) ObjxMapSlice(optionalDefault ...[](Map)) [](Map) {
if s, ok := v.data.([](Map)); ok {
return s
slice, ok := v.data.([]interface{})
if !ok {
if len(optionalDefault) == 1 {
return optionalDefault[0]
} else {
return nil
}
}
if len(optionalDefault) == 1 {
return optionalDefault[0]

result := make([]Map, len(slice))
for i := range slice {
result[i] = New(slice[i])
}
return nil

return result
}

// MustObjxMapSlice gets the value as a [](Map).
Expand Down

0 comments on commit e89b2c1

Please sign in to comment.