Skip to content
TheChatArchiveThe Chat Archive
Kimikimi-k2-0711-preview· Moonshot AIHugging Face LMArena Human Preference 140K

give me a review of this func func processOnlySearchableResourceOfType(types ...string)…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-mini-2025-04-14’s answer.
  1. User

    give me a review of this func

    func processOnlySearchableResourceOfType(types ...string) func(ctx context.Context, entity lumappsevent.Entity) error { return func(ctx context.Context, entity lumappsevent.Entity) error { event, ok := entity.Event.(*lumappsevent.EventSearchableResource) if !ok { return fmt.Errorf( "error while converting eventSearchableResource from %s, entity %+v, actual type: %+v", entity.Reference.ToString(), entity.Event, reflect.TypeOf(entity.Event).Elem(), ) }

    	if slices.Contains(types, event.Type) {
    		return nil
    	}
    
    	log.Debug().Msgf("dropping event %s as it is not in the process only list", entity.Reference.Type)
    
    	return messaging.NewDropError()
    }
    

    }

  2. Kimi Assistant

    Review of processOnlySearchableResourceOfType

    1. Purpose
      The function is a factory that returns a handler.
      The handler keeps only events whose Type is not in the supplied list and drops the rest.
      The name therefore feels backwards: it actually drops the listed types and keeps everything else.
      If the intention is the opposite (keep only the listed types), the logic is inverted.

    2. Correctness
      • The type-assertion is correct (*lumappsevent.EventSearchableResource).
      • slices.Contains is used correctly.
      • reflect.TypeOf(entity.Event).Elem() will panic if entity.Event is nil; add a nil check or use %T.
      • entity.Reference.Type is logged, but the message says “event … as it is not in the process only list”; the reader might expect the event’s own type (event.Type) to be shown.

    3. Error handling
      • Returning a typed error (messaging.NewDropError()) is idiomatic for a message bus.
      • The error returned on failed type assertion is fine, but the format string is noisy; consider a simpler message.

    4. Naming & readability
      • Rename to something that matches the behaviour, e.g. dropSearchableResourceTypes or invert the logic and call it allowOnlySearchableResourceTypes.
      • The log message is misleading; log the actual event.Type instead of entity.Reference.Type.

    5. Minor style points
      • reflect.TypeOf(entity.Event).Elem() can be replaced with %T in the format string.
      • The types slice is captured by closure; if it can be large, passing a map[string]struct{} is more efficient.

    Re-written (assuming the intention is to keep only the listed types):

    func allowOnlySearchableResourceTypes(allowed ...string) func(ctx context.Context, e lumappsevent.Entity) error {
        allowedSet := make(map[string]struct{}, len(allowed))
        for _, t := range allowed {
            allowedSet[t] = struct{}{}
        }
    
        return func(ctx context.Context, e lumappsevent.Entity) error {
            ev, ok := e.Event.(*lumappsevent.EventSearchableResource)
            if !ok {
                return fmt.Errorf("unexpected event type %T, want *EventSearchableResource", e.Event)
            }
    
            if _, ok := allowedSet[ev.Type]; ok {
                return nil // keep
            }
    
            log.Debug().
                Str("eventType", ev.Type).
                Str("ref", e.Reference.ToString()).
                Msg("dropping event, type not in allow-list")
    
            return messaging.NewDropError()
        }
    }
    

    If the original behaviour (drop the listed types) is correct, rename the function and adjust the log message accordingly.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.