Skip to content

Prepend ​

The collection with value added as its first element.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguagePrepend✓
Prepend(collection, value)the collection with value added as its first element.
Prepend(association, rule)association with rule (or a list of rules) inserted at the front; a prepended key displaces any later entry for the same key.
Typed signatures
TypePackageApplies
(collection<any>, value) -> collectioncombinatoricsalways

Domain: Collections

Details
  • Prepend(c,x)=Join({x},c)Prepend(c, x) = Join(\{x\}, c). See Join.
  • Complements Append at the other end of a collection.

Examples

3 more kept as data, checked against the oracles
Basic #
live ↗
InPrepend([a,b,c,d],x)\mathrm{Prepend}(\bigl\lbrack a, b, c, d\bigr\rbrack, x)Out[x,a,b,c,d]\bigl\lbrack x, a, b, c, d\bigr\rbrack
Scope #

A rule inserted at the front of an association

live ↗
InPrepend(Association(Rule(1,a),Rule(2,b)),Rule(3,d))\mathrm{Prepend}(\mathrm{Association}(\mathrm{Rule}(1, a), \mathrm{Rule}(2, b)), \mathrm{Rule}(3, d))OutAssociation(Rule(3,d),Rule(1,a),Rule(2,b))\mathrm{Association}(\mathrm{Rule}(3, d), \mathrm{Rule}(1, a), \mathrm{Rule}(2, b))

Several rules prepended at once

live ↗
InPrepend(Association(Rule(1,a),Rule(2,b)),[Rule(3,d),Rule(4,e)])\mathrm{Prepend}(\mathrm{Association}(\mathrm{Rule}(1, a), \mathrm{Rule}(2, b)), \bigl\lbrack\mathrm{Rule}(3, d), \mathrm{Rule}(4, e)\bigr\rbrack)OutAssociation(Rule(3,d),Rule(4,e),Rule(1,a),Rule(2,b))\mathrm{Association}(\mathrm{Rule}(3, d), \mathrm{Rule}(4, e), \mathrm{Rule}(1, a), \mathrm{Rule}(2, b))
Applications #

Repeatedly prepending grows the list by one xx each step

live ↗
InNestList(_1⁡↦Prepend(_1⁡,x),[a],5)\mathrm{NestList}(\operatorname{\_1}↦\mathrm{Prepend}(\operatorname{\_1}, x), \bigl\lbrack a\bigr\rbrack, 5)Out[[a],[x,a],[x,x,a],[x,x,x,a],[x,x,x,x,a],[x,x,x,x,x,a]]\bigl\lbrack\bigl\lbrack a\bigr\rbrack, \bigl\lbrack x, a\bigr\rbrack, \bigl\lbrack x, x, a\bigr\rbrack, \bigl\lbrack x, x, x, a\bigr\rbrack, \bigl\lbrack x, x, x, x, a\bigr\rbrack, \bigl\lbrack x, x, x, x, x, a\bigr\rbrack\bigr\rbrack
Properties #

Prepend(c,x)=Join({x},c)Prepend(c, x) = Join(\{x\}, c). See Join

live ↗
InPrepend([1,2,3],0)=Join([0],[1,2,3])\mathrm{Prepend}(\bigl\lbrack1, 2, 3\bigr\rbrack, 0)=\mathrm{Join}(\bigl\lbrack0\bigr\rbrack, \bigl\lbrack1, 2, 3\bigr\rbrack)OutTrue\mathrm{True}
Possible issues #

A list argument is added as one element, not spliced in

live ↗
InPrepend([a,b,c],[x,y])\mathrm{Prepend}(\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack x, y\bigr\rbrack)Out[[x,y],a,b,c]\bigl\lbrack\bigl\lbrack x, y\bigr\rbrack, a, b, c\bigr\rbrack
About
Examples9
Checked againstWolfram Language 8 agreemathlib4 4 agree
CrosswalkWolfram Language

Implementation

mappedmathlib4packages/oracle/src/mappings.ts

The value consed onto the list; a list value onto a list of scalars fails to elaborate (ours nests it as one element), as does an association.

See also: Append, Join