Function intersperse

  • Add the given separator between each element of the given iterable or asynchronous iterable.

    Example

    const intersperseComma = intersperse(",");
    intersperseComma([1, 2, 3]); // [1, ",", 2, ",", 3]

    Type Parameters

    • Separator

    Parameters

    • separator: Separator

      Separator to add between each element.

    Returns (<Item>(iterable) => {
        [iterator]() => IterableIterator<Separator | Item>;
        next(...args) => IteratorResult<Separator | Item, any>;
        return?(value?) => IteratorResult<Separator | Item, any>;
        throw?(e?) => IteratorResult<Separator | Item, any>;
    })

    Curried function with separator in context.

      • <Item>(iterable): {
            [iterator]() => IterableIterator<Separator | Item>;
            next(...args) => IteratorResult<Separator | Item, any>;
            return?(value?) => IteratorResult<Separator | Item, any>;
            throw?(e?) => IteratorResult<Separator | Item, any>;
        }
      • Type Parameters

        • Item

        Parameters

        • iterable: IsomorphicIterable<Item>

        Returns {
            [iterator]() => IterableIterator<Separator | Item>;
            next(...args) => IteratorResult<Separator | Item, any>;
            return?(value?) => IteratorResult<Separator | Item, any>;
            throw?(e?) => IteratorResult<Separator | Item, any>;
        }

        • [iterator]:function
          • Returns IterableIterator<Separator | Item>

        • next:function
          • Parameters

            • Rest ...args: [] | [undefined]

            Returns IteratorResult<Separator | Item, any>

        • return?:function
          • Parameters

            • Optional value: any

            Returns IteratorResult<Separator | Item, any>

        • throw?:function
          • Parameters

            • Optional e: any

            Returns IteratorResult<Separator | Item, any>