Quadrille.singleton
Declares that one value is meant to be shared by every cell — the whole quadrille holds the same instance, not one copy per cell. The call changes nothing: it returns the value untouched, and exists to say so where a reader will look.
fill(value) already stores the very same reference in every cell it fills, so Quadrille.singleton(v) is a statement of intent rather than a transformation. That intent matters once the value is an object with state: a shared instance means a change made through one cell is visible through all of them, which is what a wall, a counter or a rule object usually wants.
Example
Note
The opposite is
Quadrille.factory: a function run per cell, so every cell receives its own value. A quadrille filled with a singleton is one object seen many times; a quadrille filled with a factory is many objects.
What this page's examples use
- p5.quadrille
drawQuadrillecreateQuadrillecellLengthfillreadsingleton- p5.js
createCanvasbackgroundCENTER- JavaScript
console.assert
Names the analysis can prove are called, and the line each one is documented on. Local variables and members of an unknown receiver are left out.