Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » lists and sequences » join
next | previous | forward | backward | up | index | toc

# join -- join lists, sequences, and iterable objects

- Usage:
    `join(A, B, ...)`
- Inputs:
  - A, a basic list,
  - B, a basic list, or any instance of a class with the iterator method installed
- Outputs:
  - Z, a basic list or an iterator,

## Description

join(A, B, ...) joins the elements of the lists or sequences A, B, ... into a single list or sequence. The inputs may belong to different classes; the class of the result will match the class of the first argument passed to join.

    i1 : join( {1,2,3}, (4,5,6), (7,8,9) )

    o1 = {1, 2, 3, 4, 5, 6, 7, 8, 9}

    o1 : List

    i2 : join( (1,2,3), {4,5,6}, {7}, (8,9,10) )

    o2 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

    o2 : Sequence

The operator | is a convenient shorthand for joining two inputs of the same class.

    i3 : {1,2,3} | {4,5,6}

    o3 = {1, 2, 3, 4, 5, 6}

    o3 : List

    i4 : (1,2,3) | (4,5,6)

    o4 = (1, 2, 3, 4, 5, 6)

    o4 : Sequence

If the first argument is a list or sequence and any later arguments are instances of a class with the iterator method installed, then these instances are converted to sequences and are then joined.

    i5 : join({1, 2, 3}, iterator {4, 5, 6})

    o5 = {1, 2, 3, 4, 5, 6}

    o5 : List

If the first argument is not a list or sequence, then an Iterator object is returned that iterates through each argument sequentially, provided that each argument is an iterable object.

    i6 : join(iterator {1, 2, 3}, {4, 5, 6})

    o6 = iterator (iterator {1, 2, 3}, {4, 5, 6})

    o6 : Iterator

    i7 : toList oo

    o7 = {1, 2, 3, 4, 5, 6}

    o7 : List

## See also

- concatenate -- join strings
- demark -- insert a string between elements of a list of strings
- flatten -- flatten a nested list or a matrix
- mingle -- mingle elements of several lists
- List | List -- join lists, sequences or arrays
- lists and sequences -- a detailed overview of lists and sequences in Macaulay2

## For the programmer

The object join is a compiled function.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/join-doc.m2:53:0.