FlexList
From Erights
Kevin Reid (Talk | contribs) (spec cat) |
(document push) |
||
(2 intermediate revisions not shown) | |||
Line 6: | Line 6: | ||
{{XXX|Document the FlexList methods here.}} | {{XXX|Document the FlexList methods here.}} | ||
+ | |||
+ | {{instance msgdoc|push|1|<var>new</var> :valueType|[[void]]}} | ||
+ | |||
+ | Inserts <var>new</var> after the last element. {{specbycode|{{this}}.replace({{this}}.size(), {{this}}.size(), [new], 0, 1)}} | ||
==Protocol inherited from EList== | ==Protocol inherited from EList== |
Latest revision as of 21:39, 23 May 2009
FlexList is the basic mutable sequence type in ELib. It is a subtype of EList.
FlexLists are typically constructed from ConstLists, or other FlexLists, by #diverge/0.
Protocol
XXX Document the FlexList methods here.
push/1
- Signature: push(new :valueType) :void
Inserts new after the last element. Equivalent to thisFlexList.replace(thisFlexList.size(), thisFlexList.size(), [new], 0, 1)
.
Protocol inherited from EList
XXX This transclusion-for-testing is experimental.
XXX Used a program to generate this list of msgdoc headers from E-on-Java. Clean up and write specs.
? def abcd := fn c { c.diverge() }(["a", "b", "c", "d"]); null ? def ConstList := List
? /** Coercion-inhibiting guard wrapper. For example, Really[ConstList] will accept only ConstLists and not things which coerce to them. */ > def Really { > to get(guard) { > return def reallyGuard { > to coerce(specimen, optEjector) { > def coerced := guard.coerce(specimen, optEjector) > if (coerced != specimen) { > throw.eject(optEjector, E.toQuote(coerced) + " must be same as original specimen " + E.toQuote(specimen)) > } > return coerced > } > } > } > }; null
add/1
Concatenates (snapshots of) this list and other.
XXX If they have a common class, we should use it.
XXX The above remark is from the original javadoc. Is this still the intended design? Perhaps it refers to e.g. String + String = String. If so, clarify whether or not it also means e.g. FlexList + FlexList = FlexList. --Kevin Reid 17:38, 25 March 2009 (CDT)
? abcd.add(abcd.run(1, 3)) :Really[ConstList] # value: ["a", "b", "c", "d", "b", "c"]
XXX type error check, other cases, which one is first
asKeys/0
- Signature: asKeys() :ConstMap
Returns a ConstMap whose keys are the elements of this EList and values are null, with the first occurrence of duplicates kept.
? abcd.asKeys() # value: ["a" => null, "b" => null, "c" => null, "d" => null] ? def abcbd := abcd(0, 3) + abcd(1, 2) + abcd(3, 4) # value: ["a", "b", "c", "b", "d"] ? abcbd.asKeys() # value: ["a" => null, "b" => null, "c" => null, "d" => null]
asMap/0
- Signature: asMap() :ConstMap
Returns a ConstMap whose keys are the indexes and values are the values of this EList, in the same order as this EList.
? abcd.asMap() # value: [0 => "a", 1 => "b", 2 => "c", 3 => "d"]
asSet/0
- Signature: asSet() :ConstSet
contains/1
- Signature: contains(_ :null) :Boolean
diverge/0
- Signature: diverge() :FlexList
diverge/1
- Signature: diverge(_ :Guard) :FlexList
fetch/2
get/1
- Signature: get(index :Integer) :valueType
Return the element at index.
? abcd[0] # value: "a" ? abcd[2] # value: "c" ? abcd[-1] # problem: <XXX specify form of error> ? abcd[4] # problem: <XXX specify form of error>
getArray/0
- Signature: getArray() :any
getArray/1
- Signature: getArray(_ :nullOk[Class]) :any
getArray/3
includes/1
- Signature: includes(_ :nullOk[EList]) :Boolean
indexOf1/1
- Signature: indexOf1(_) :Integer
indexOf1/2
iterate/1
last/0
- Signature: last() :any
lastIndexOf1/1
- Signature: lastIndexOf1(_) :Integer
lastIndexOf1/2
lastStartOf/1
lastStartOf/2
multiply/1
printOn/4
- Signature: printOn(_ :String, _ :String, _ :String, out :TextWriter) :void
readOnly/0
- Signature: readOnly() :EList
Return an EList which is a read-only view of this list. If this list is immutable the result may be the same as this list.
run/2
Return a ConstList containing the subsequence of elements in this list starting with element index start and ending with the element before index end.
? abcd.run(1, 3) :Really[ConstList] # value: ["b", "c"] ? abcd.run(0, abcd.size()) :Really[ConstList] # value: ["a", "b", "c", "d"] ? ESpec.requireWrongArgsFail(abcd, "run", [0..!(abcd.size()), 0..!(abcd.size())])
XXX the above 'ESpec' is an idea about defining some utilities
run/1
Equivalent to thisFlexList.run(start, thisFlexList.size())
.
? abcd.run(1) :Really[ConstList] # value: ["b", "c", "d"] ? abcd.run(0) :Really[ConstList] # value: ["a", "b", "c", "d"]
size/0
- Signature: size() :Integer
Return the current number of elements of this list.
? abcd.size() :Really[int] # value: 4
snapshot/0
- Signature: snapshot() :ConstList
Return a ConstList with the current elements of this list.
XXX test this vs. mutation
? abcd.snapshot() :Really[ConstList] # value: ["a", "b", "c", "d"]
sort/0
- Signature: sort() :ConstList
sort/1
startOf/1
startOf/2
valueType/0
- Signature: valueType() :Guard
with/1
- Signature: with(value) :ConstList
Return a ConstList with the current elements of this list, followed by the one additional element value.
Equivalent to thisFlexList.with(thisFlexList.size(), value :any)
.
? abcd.with("e") :Really[ConstList] # value: ["a", "b", "c", "d", "e"] ? fn c { c.diverge() }([]).with(1) :Really[ConstList] # value: [1]
XXX more tests?
with/2
Return a ConstList with the current elements of this list except that the element at index is value. Or, by cases:
- If index is less than the #size/0, then that element is replaced in the result list.
- If index is equal to #size/0, then value is an additional element and the size is one greater. (This is equivalent to
thisFlexList + [value]
.) - Otherwise, the index is out of bounds. XXX specify error
XXX write tests
- This page is a stub; it should be expanded with more information. If doing so, check the original E web site and the mailing list archives for content which could be moved into this page.