<commit_before>import delayP from '@redux-saga/delay-p'
import * as is from '@redux-saga/is'
import { IO, SELF_CANCELLATION } from '@redux-saga/symbols'
import { check, createSetContextWarning, identity } from './utils'
import * as effectTypes from './effectTypes'

const TEST_HINT =
  '\n(HINT: if you are getting this errors in tests, consider using createMockTask from @redux-saga/testing-utils)'

const makeEffect = (type, payload) => ({
  [IO]: true,
  // this property makes all/race distinguishable in generic manner from other effects
  // currently it's not used at runtime at all but it's here to satisfy type systems
  combinator: false,
  type,
  payload,
})

const isForkEffect = eff => eff && eff[IO] && eff.type === effectTypes.FORK

export const detach = eff => {
  if (process.env.NODE_ENV !== 'production') {
    check(eff, isForkEffect, 'detach(eff): argument must be a fork effect')
  }
  return makeEffect(effectTypes.FORK, { ...eff.payload, detached: true })
}

export function take(patternOrChannel = '*', multicastPattern) {
  if (process.env.NODE_ENV !== 'production' && arguments.length) {
    check(arguments[0], is.notUndef, 'take(patternOrChannel): patternOrChannel is undefined')
  }
  if (is.pattern(patternOrChannel)) {
    return makeEffect(effectTypes.TAKE, { pattern: patternOrChannel })
  }
  if (is.multicast(patternOrChannel) && is.notUndef(multicastPattern) && is.pattern(multicastPattern)) {
    return makeEffect(effectTypes.TAKE, { channel: patternOrChannel, pattern: multicastPattern })
  }
  if (is.channel(patternOrChannel)) {
    return makeEffect(effectTypes.TAKE, { channel: patternOrChannel })
  }
  if (process.env.NODE_ENV !== 'production') {
    throw new Error(`take(patternOrChannel): argument ${patternOrChannel} is not valid channel or a valid pattern`)
  }
}

export const takeMaybe = (...args) => {
  const eff = take(...args)
  eff.payload.maybe = true
  return eff
}

export function put(channel, action) {
  if (process.env.NODE_ENV !== 'production') {
    if (arguments.length > 1) {
      check(channel, is.notUndef, 'put(channel, action): argument channel is undefined')
      check(channel, is.channel, `put(channel, action): argument ${channel} is not a valid channel`)
      check(action, is.notUndef, 'put(channel, action): argument action is undefined')
    } else {
      check(channel, is.notUndef, 'put(action): argument action is undefined')
    }
  }
  if (is.undef(action)) {
    action = channel
    // `undefined` instead of `null` to make default parameter work
    channel = undefined
  }
  return makeEffect(effectTypes.PUT, { channel, action })
}

export const putResolve = (...args) => {
  const eff = put(...args)
  eff.payload.resolve = true
  return eff
}

export function all(effects) {
  const eff = makeEffect(effectTypes.ALL, effects)
  eff.combinator = true
  return eff
}

export function race(effects) {
  const eff = makeEffect(effectTypes.RACE, effects)
  eff.combinator = true
  return eff
}

// this match getFnCallDescriptor logic
const validateFnDescriptor = (effectName, fnDescriptor) => {
  check(fnDescriptor, is.notUndef, `${effectName}: argument fn is undefined or null`)

  if (is.func(fnDescriptor)) {
    return
  }

  let context = null
  let fn

  if (is.array(fnDescriptor)) {
    ;[context, fn] = fnDescriptor
    check(fn, is.notUndef, `${effectName}: argument of type [context, fn] has undefined or null \`fn\``)
  } else if (is.object(fnDescriptor)) {
    ;({ context, fn } = fnDescriptor)
    check(fn, is.notUndef, `${effectName}: argument of type {context, fn} has undefined or null \`fn\``)
  } else {
    check(fnDescriptor, is.func, `${effectName}: argument fn is not function`)
    return
  }

  if (context && is.string(fn)) {
    check(context[fn], is.func, `${effectName}: context arguments has no such method - "${fn}"`)
    return
  }

  check(fn, is.func, `${effectName}: unpacked fn argument (from [context, fn] or {context, fn}) is not a function`)
}

function getFnCallDescriptor(fnDescriptor, args) {
  let context = null
  let fn

  if (is.func(fnDescriptor)) {
    fn = fnDescriptor
  } else {
    if (is.array(fnDescriptor)) {
      ;[context, fn] = fnDescriptor
    } else {
      ;({ context, fn } = fnDescriptor)
    }

    if (context && is.string(fn) && is.func(context[fn])) {
      fn = context[fn]
    }
  }

  return { context, fn, args }
}

const isNotDelayEffect = fn => fn !== delay

export function call(fnDescriptor, ...args) {
  if (process.env.NODE_ENV !== 'production') {
    check(
      fnDescriptor,
      isNotDelayEffect,
      'instead of writing `yield call(delay, ms)` where delay is an effect from `redux-saga/effects` you should write `yield delay(...)`',
    )
    validateFnDescriptor('call', fnDescriptor)
  }
  return makeEffect(effectTypes.CALL, getFnCallDescriptor(fnDescriptor, args))<commit_msg>Bring back including correct numbers in validation error for call(delay, ms)<commit_after>import delayP from '@redux-saga/delay-p'
import * as is from '@redux-saga/is'
import { IO, SELF_CANCELLATION } from '@redux-saga/symbols'
import { check, createSetContextWarning, identity } from './utils'
import * as effectTypes from './effectTypes'

const TEST_HINT =
  '\n(HINT: if you are getting this errors in tests, consider using createMockTask from @redux-saga/testing-utils)'

const makeEffect = (type, payload) => ({
  [IO]: true,
  // this property makes all/race distinguishable in generic manner from other effects
  // currently it's not used at runtime at all but it's here to satisfy type systems
  combinator: false,
  type,
  payload,
})

const isForkEffect = eff => eff && eff[IO] && eff.type === effectTypes.FORK

export const detach = eff => {
  if (process.env.NODE_ENV !== 'production') {
    check(eff, isForkEffect, 'detach(eff): argument must be a fork effect')
  }
  return makeEffect(effectTypes.FORK, { ...eff.payload, detached: true })
}

export function take(patternOrChannel = '*', multicastPattern) {
  if (process.env.NODE_ENV !== 'production' && arguments.length) {
    check(arguments[0], is.notUndef, 'take(patternOrChannel): patternOrChannel is undefined')
  }
  if (is.pattern(patternOrChannel)) {
    return makeEffect(effectTypes.TAKE, { pattern: patternOrChannel })
  }
  if (is.multicast(patternOrChannel) && is.notUndef(multicastPattern) && is.pattern(multicastPattern)) {
    return makeEffect(effectTypes.TAKE, { channel: patternOrChannel, pattern: multicastPattern })
  }
  if (is.channel(patternOrChannel)) {
    return makeEffect(effectTypes.TAKE, { channel: patternOrChannel })
  }
  if (process.env.NODE_ENV !== 'production') {
    throw new Error(`take(patternOrChannel): argument ${patternOrChannel} is not valid channel or a valid pattern`)
  }
}

export const takeMaybe = (...args) => {
  const eff = take(...args)
  eff.payload.maybe = true
  return eff
}

export function put(channel, action) {
  if (process.env.NODE_ENV !== 'production') {
    if (arguments.length > 1) {
      check(channel, is.notUndef, 'put(channel, action): argument channel is undefined')
      check(channel, is.channel, `put(channel, action): argument ${channel} is not a valid channel`)
      check(action, is.notUndef, 'put(channel, action): argument action is undefined')
    } else {
      check(channel, is.notUndef, 'put(action): argument action is undefined')
    }
  }
  if (is.undef(action)) {
    action = channel
    // `undefined` instead of `null` to make default parameter work
    channel = undefined
  }
  return makeEffect(effectTypes.PUT, { channel, action })
}

export const putResolve = (...args) => {
  const eff = put(...args)
  eff.payload.resolve = true
  return eff
}

export function all(effects) {
  const eff = makeEffect(effectTypes.ALL, effects)
  eff.combinator = true
  return eff
}

export function race(effects) {
  const eff = makeEffect(effectTypes.RACE, effects)
  eff.combinator = true
  return eff
}

// this match getFnCallDescriptor logic
const validateFnDescriptor = (effectName, fnDescriptor) => {
  check(fnDescriptor, is.notUndef, `${effectName}: argument fn is undefined or null`)

  if (is.func(fnDescriptor)) {
    return
  }

  let context = null
  let fn

  if (is.array(fnDescriptor)) {
    ;[context, fn] = fnDescriptor
    check(fn, is.notUndef, `${effectName}: argument of type [context, fn] has undefined or null \`fn\``)
  } else if (is.object(fnDescriptor)) {
    ;({ context, fn } = fnDescriptor)
    check(fn, is.notUndef, `${effectName}: argument of type {context, fn} has undefined or null \`fn\``)
  } else {
    check(fnDescriptor, is.func, `${effectName}: argument fn is not function`)
    return
  }

  if (context && is.string(fn)) {
    check(context[fn], is.func, `${effectName}: context arguments has no such method - "${fn}"`)
    return
  }

  check(fn, is.func, `${effectName}: unpacked fn argument (from [context, fn] or {context, fn}) is not a function`)
}

function getFnCallDescriptor(fnDescriptor, args) {
  let context = null
  let fn

  if (is.func(fnDescriptor)) {
    fn = fnDescriptor
  } else {
    if (is.array(fnDescriptor)) {
      ;[context, fn] = fnDescriptor
    } else {
      ;({ context, fn } = fnDescriptor)
    }

    if (context && is.string(fn) && is.func(context[fn])) {
      fn = context[fn]
    }
  }

  return { context, fn, args }
}

const isNotDelayEffect = fn => fn !== delay

export function call(fnDescriptor, ...args) {
  if (process.env.NODE_ENV !== 'production') {
    const arg0 = typeof args[0] === 'number' ? args[0] : 'ms'
    check(
      fnDescriptor,
      isNotDelayEffect,
      `instead of writing \`yield call(delay, ${arg0})\` where delay is an effect from \`redux-saga/effects\` you should write \`yield delay(${arg0})\``,
    )
    validateFnDescriptor('call', fnDescriptor)
  }
  return makeEffect(effectTypes.CALL, getFnCallDescriptor(fnDescriptor, args))
{'fraction_non_alphanumeric': 0.13561727143725927, 'fraction_numerical': 0.0009122237989053314, 'mean_word_length': 3.848648648648649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5373869', 'n_tokens_mistral': 3099, 'n_tokens_neox': 3058, 'n_words': 892}