<commit_before>import * as React from "react";
import { debounce, Cancelable, DebounceSettings } from "lodash";

type CancelableHOF = <T extends (...args: any[]) => any>(
  func: T,
  ...rest
) => T & Cancelable;

type Tail<T extends any[]> = ((...args: T) => any) extends (
  _: any,
  ...tail: infer Rest
) => any
  ? Rest
  : [];

/**
 * When a callback is deferred (eg. with debounce) it may
 * try to run when the component is no longer rendered
 *
 * useCallbackWith automatically runs a clean up function
 * with React.useEffect
 */
function useCallbackWith<
  H extends CancelableHOF,
  F extends (...args: any[]) => any
>(hof: H, callback: F, ...tail: Tail<Parameters<H>>): typeof wrapped {
  const wrapped = React.useCallback(hof(callback, ...tail), [...tail]);

  React.useEffect(() => {
    return wrapped.cancel;
  }, [wrapped]);<commit_msg>Add a TODO<commit_after>import * as React from "react";
import { debounce, Cancelable, DebounceSettings } from "lodash";

type CancelableHOF = <T extends (...args: any[]) => any>(
  func: T,
  ...rest
) => T & Cancelable;

type Tail<T extends any[]> = ((...args: T) => any) extends (
  _: any,
  ...tail: infer Rest
) => any
  ? Rest
  : [];

/**
 * When a callback is deferred (eg. with debounce) it may
 * try to run when the component is no longer rendered
 *
 * useCallbackWith automatically runs a clean up function
 * with React.useEffect
 */
// TODO: Allow an option to flush instead of cancel
function useCallbackWith<
  H extends CancelableHOF,
  F extends (...args: any[]) => any
>(hof: H, callback: F, ...tail: Tail<Parameters<H>>): typeof wrapped {
  const wrapped = React.useCallback(hof(callback, ...tail), [...tail]);

  React.useEffect(() => {
    return wrapped.cancel;
  }, [wrapped]);
{'fraction_non_alphanumeric': 0.1644849174729653, 'fraction_numerical': 0.0, 'mean_word_length': 3.4732824427480917, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '480041', 'n_tokens_mistral': 563, 'n_tokens_neox': 558, 'n_words': 196}