hunk.code_window:   for (const [stateValue, getValue] of patterns) {
       if (state.matches(stateValue)) {
         return getValue(state);
       }
     }
  
hunk.labels: keep replace replace keep keep keep
hunk.after_edit:     if (resolvedState.matches(stateValue)) {
         return getValue(resolvedState);
  
hunk.file_path: src/match.ts
hunk.type: replace
file: import { State } from './State';
  import { StateValue, EventObject } from './types';
  
  export type ValueFromStateGetter<T, TContext, TEvent extends EventObject> = (
    state: State<TContext, TEvent>
  ) => T;
  
  export type StatePatternTuple<T, TContext, TEvent extends EventObject> = [
    StateValue,
    ValueFromStateGetter<T, TContext, TEvent>
  ];
  
  export function matchState<T, TContext, TEvent extends EventObject>(
    state: State<TContext, TEvent>,
    patterns: Array<StatePatternTuple<T, TContext, TEvent>>,
    defaultValue: ValueFromStateGetter<T, TContext, TEvent>
  ): T {
    for (const [stateValue, getValue] of patterns) {
      if (state.matches(stateValue)) {
        return getValue(state);
      }
    }
  
    return defaultValue(state);
  }
  