E07870: require an Integer value or function/function delegate

Category: E07xxx Full resolution · Reported in phase: FULL_RESOLUTION · Classification: INTEGER_VAR_OR_FUNCTION_OR_DELEGATE_REQUIRED · All error codes

What went wrong

This context accepts either an Integer value OR a function/delegate, but you provided something else.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 1345 (Why does my stream 'head' fail when I give it a Date v...)

How to fix it

  1. Provide Integer value or function delegate as appropriate
  2. Check context requirements

Common causes

  • Wrong type for context
  • Missing required argument

See also

  • E07870: Integer or function required (this error)
  • E07860: function delegate required

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07870: require an Integer value or function/function delegate

#!ek9
defines module error.e07870.bad

  defines function

    firstOnes()
      <- rtn as List of String: List()
      howMany <- "two"

      //head takes an Integer, or a function that gives one
      cat ["a", "b", "c"] | head howMany > rtn

Fixed: Give head an Integer, or a function that returns one

#!ek9
defines module error.e07870.good

  defines function

    howManyToTake()
      <- rtn as Integer: 2

    //Option 1: an Integer
    firstOnes()
      <- rtn as List of String: List()
      howMany <- 2
      cat ["a", "b", "c"] | head howMany > rtn

    //Option 2: a function that gives an Integer
    firstFew()
      <- rtn as List of String: List()
      cat ["a", "b", "c"] | head howManyToTake > rtn

Questions and answers

These Q&A entries show E07870 and its fix: