query
On this page

intersperse

lib.intersperse

Docs pulled from | This Revision | 10 minutes ago


Place an element between each element of a list

Inputs

separator
Separator to add between elements
list
Input list

Type

intersperse :: a -> [a] -> [a]

Examples

lib.strings.intersperse usage example

intersperse "/" ["usr" "local" "bin"]
=> ["usr" "/" "local" "/" "bin"].
(lib.strings.intersperse)

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

intersperse =
    separator:
    list:
    if list == [] || length list == 1
    then list
    else tail (lib.concatMap (x: [separator x]) list);