1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
--- status: DRAFT
--- author(s): L. Gold
--- notes: should "mapping over lists" be in the see also spot?
--- The apply(HashTable,Function) in the "ways to use" section doesn't seem
--- to have disappeared in my documentation, even though it is obsolete.
document {
Key => apply,
Headline => "apply a function to each element",
Usage => "apply(L,f) or apply(L1,L2,f)",
SeeAlso => {"applyKeys", "applyPairs", "applyValues", "applyTable", "lists and sequences"}
}
document {
Key => (apply,BasicList,Function),
Headline => "apply a function to each element of a list",
Usage => "apply(L,f)",
Inputs => {
"L" => BasicList,
"f" => Function => "with one argument",
},
Outputs => {
BasicList =>
{"obtained by applying ", TT "f", " to each element of ", TT "L"}
},
"The result will have the same class as ", TT "L", ".",
EXAMPLE {
"apply({1,3,5,7}, i -> i^2)",
"apply([1,3,5,7], i -> i^2)",
"apply((1,3,5,7), i -> i^2)"
},
SeeAlso => {(symbol /, VisibleList, Function), (symbol \,Function,VisibleList)}
}
document {
Key => (apply,BasicList,BasicList,Function),
Headline => "apply a function to pairs of elements, one from each list",
Usage => "apply(L1,L2,f)",
Inputs => {
"L1" => BasicList,
"L2" => BasicList => {"of the same length as ", TT "L1"},
"f" => Function => "with two arguments",
},
Outputs => {
BasicList => {
"with the ith element obtained by evaluating ", TT "f(L1_i,L2_i)"}
},
"The result will have the same class as the class of ", TT "L1", " and ", TT "L2", ".",
EXAMPLE {
"apply({1,2,3}, {100,200,300}, (i,j) -> i+j)",
"apply([1,2,3], [100,200,300], (i,j) -> i+j)",
"apply((1,2,3), (100,200,300), (i,j) -> i+j)"
},
}
document {
Key => (apply,ZZ,Function),
Headline => "apply a function to {0,..., n-1}",
Usage => "apply(n,f)",
Inputs => {
"n" => ZZ,
"f" => Function => "with one argument",
},
Outputs => {
List => {"obtained by applying ", TT "f", " to the list of integers {0,..., n-1}"}
},
"The command ", TT " apply(n,f)", " is equivalent to ", TT "apply(toList(0 .. n-1),f)", ".",
EXAMPLE {
"apply(10, i -> i^2)"
},
}
|