w3bstream
w3bstream copied to clipboard
`distinct` op
distinct always works with the operations window or group, the return value is a unique key.
example code:
// rxgo.Just(1, 2, 2, 3, 1, 4, 4, 5, 6, 4)().Distinct(distinct)
func distinct(_ context.Context, item interface{}) (interface{}, error) {
// 1.Serialize
b, err := json.Marshal(item.V.(models.Customer))
if err != nil {
l.Error(err)
}
// 2.Invoke wasm code
code := ins.HandleEvent(ctx, "distinct", b).Code
l.Info(fmt.Sprintf("distinct wasm code %d", code))
// 3.Get & parse data
if code < 0 {
l.Error(errors.New(fmt.Sprintf("%v %s error.", item.V.(models.Customer), "distinct")))
//TODO handle exceptions
return "error"
}
rb, ok := ins.GetResource(uint32(code))
defer ins.RmvResource(ctx, uint32(code))
if !ok {
l.Error(errors.New("groupByAge result not found"))
//TODO handle exceptions
return "error"
}
distinct := string(rb)
return distinct
}