guregu / null

reasonable handling of nullable values
BSD 2-Clause "Simplified" License
1.84k stars 238 forks source link

IsFill method support #43

Closed apopov-app closed 7 months ago

apopov-app commented 5 years ago

This method allows you to determine whether the field was filled with marchal, which is useful for different merge models. For example: ` type MyModel struct { Name null.String Family null.String }

oldModel := LoadFromDb() // return MyModel with fields: Name: John, Family: Smith newModel := LoadFromRequest() // return MyModel with fields: Name: Alex (json: { Name: Alex })

//merge method if newModel.Name.IsFill() { oldModel.Name = newModel.Name }

if newModel.Family.IsFill() { oldModel.Family = newModel.Family }

// Result: MyModel with fields: Name: Alex, Family: Smith `

sorry for mistakes, i write with ipad

guregu commented 4 years ago

I like this idea and may consider it for the next major version.