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

# VisibleList / Function -- apply a function to elements of a list

- Operator: /
- Usage:
    `x/f`
    `f\x`
- Inputs:
  - x, a visible list, a list, a sequence, an array, a tally, a set, or a string
  - f, a function, a command, a self initializing type, or a ring map
- Outputs:
  - a visible list, the list, tally, or set obtained by applying f to each element of x; it has the same type as x has

## Description

The function apply does the same thing.

The operator / is left associative, which means that w / f / g is interpreted as (w / f) / g. The operator \ is right associative, so g \ f \ w is interpreted as g \ (f \ w). Both operators have parsing precedence lower than that of @@, which means that the previous two expressions are equivalent to w / g @@ f and g @@ f \ w, respectively. See precedence of operators.

    i1 : f = x -> x+1

    o1 = f

    o1 : FunctionClosure

    i2 : g = x -> 2*x

    o2 = g

    o2 : FunctionClosure

    i3 : g \ (1 .. 10)

    o3 = (2, 4, 6, 8, 10, 12, 14, 16, 18, 20)

    o3 : Sequence

    i4 : (1 .. 10) / g

    o4 = (2, 4, 6, 8, 10, 12, 14, 16, 18, 20)

    o4 : Sequence

    i5 : f \ g \ (1 .. 10)

    o5 = (3, 5, 7, 9, 11, 13, 15, 17, 19, 21)

    o5 : Sequence

    i6 : f @@ g \ (1 .. 10)

    o6 = (3, 5, 7, 9, 11, 13, 15, 17, 19, 21)

    o6 : Sequence

    i7 : set (1 .. 10)

    o7 = set {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

    o7 : Set

    i8 : g \ oo

    o8 = set {16, 18, 2, 20, 4, 6, 8, 10, 12, 14}

    o8 : Set

    i9 : R = QQ[x];

    i10 : f = map(R,R,{x^2})

                       2
    o10 = map (R, R, {x })

    o10 : RingMap R <-- R

    i11 : f \ {x,x^2,x^3,x^4}

            2   4   6   8
    o11 = {x , x , x , x }

    o11 : List

## Code

    ../../m2/classes.m2:97:42-97:61: --source code:
    VisibleList /  Function := VisibleList => (v,f) -> apply(v,f)

## Ways to use this method:

- `List / Command`
- `List / Function`
- `List / SelfInitializingType`
- `Set / Command`
- `Set / Function`
- `String / Command`
- `String / Function`
- `VirtualTally / Command`
- `VirtualTally / Function`
- `VisibleList / Command`
- VisibleList / Function -- apply a function to elements of a list
- `VisibleList / RingMap`
- `VisibleList / SelfInitializingType`

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