Herbert Vojčík 4a2197dc1d Remove some github urls. | %!s(int64=8) %!d(string=hai) anos | |
---|---|---|
src | %!s(int64=9) %!d(string=hai) anos | |
.gitignore | %!s(int64=9) %!d(string=hai) anos | |
Gruntfile.js | %!s(int64=9) %!d(string=hai) anos | |
LICENSE-MIT | %!s(int64=9) %!d(string=hai) anos | |
README.md | %!s(int64=9) %!d(string=hai) anos | |
bower.json | %!s(int64=8) %!d(string=hai) anos | |
deploy.js | %!s(int64=9) %!d(string=hai) anos | |
devel.js | %!s(int64=9) %!d(string=hai) anos | |
index.html | %!s(int64=9) %!d(string=hai) anos | |
local.amd.json | %!s(int64=9) %!d(string=hai) anos | |
package.json | %!s(int64=8) %!d(string=hai) anos |
Get / set hierarchical data using array-like indexes.
The Lyst index (aka yndex) an array of elements: either strings, numbers or a sub-arrays. These are used to denote the (relative) location of a piece of data in a hierarchical object, and is used to read or write from / to this position.
Elements of a path are equivalent to elements of paths in classic file systems: each elements is one step deeper in a tree hierarchy. Thus, to read a data denoted by a path, Lyst starts from actual position, reads the contents denoted by first element, use the result to read the contents denoted by second elements etc. until the end. To write the data, the algorithm is similar to reading one, byt the last element is used to write the data instead.
foo at: aString
is performed;foo at: aString put: value
is performed;foo at: aNumber
is performed;foo at: aNumber put: value
is performed;#(bar)
is read from foo, foo bar
is performed;#(bar)
is written to foo, foo bar: value
is performed.Object >> atLyst: aCollection ifAbsent: aBlock
For example container atLyst: #((todos) 1 done) ifAbsent: [...]'
essentially does
| x |
x := container todos at: 1.
^ x at: 'done'
But, whenever:
container
fails to perform todos
, orcontainer todos
fails to perform at:ifAbsent:
, orcontainer todos
does not contain index 1, orcontainer todos at: 1
fails to perform at:ifAbsent:
, orcontainer todos at: 1
does not contain index 'done',the ifAbsent
block value is returned.
Object >> atLyst: aCollection ifAbsent: aBlock put: anObject
For example container atLyst: #((todos) 1 done) ifAbsent: [...] put: 'foo'
essentially does
| x |
x := container todos at: 1.
^ x at: 'done' put: 'foo'
But, whenever:
container
fails to perform todos
, orcontainer todos
fails to perform at:ifAbsent:
, orcontainer todos
does not contain index 1, orcontainer todos at: 1
fails to do at:put:
,the ifAbsent
block value is returned.
Lyst class >> parse: aString
Parses a string to get a proper array index to use with atLyst:
API.
The syntax is resembling Smalltalk literal array syntax very closely.
For example Lyst parse: '(value)'
and Lyst parse: '(todos) 1 done'
produce #((value))
and #((todos) 1 done)
as results.
Syntactic sugar: as (foo)
happens often, to denote unary selector,
it can be written equivalently as ~foo
, to improve readability.
So above Lyst indexes' parseable string representation
would likely be written '~value'
and '~todos 1 done'
instead.