Skip to content

__IterableList__

Hyomoto edited this page Jun 24, 2021 · 3 revisions
Jump To Go Back Methods Abstract Variables

IterableList( )

Implements: Struct

This is an interface for building python-style lists. To make a new data structure, inherit this constructor and implement the first eight methods. IterableLists are compatible with one another, despite any underlying differences in structure choice. They can be used as stacks, queues, unordered or ordered lists, and sets. When used as an ordered list, binary search is used for insertion and traversal, but this behavior can be changed by overwriting __Search.

Methods

Jump To top first last swap remove count filter sort unique union intersection difference reverse shuffle find contains copy is_empty no_duplicates order from_input to_output from_array to_array from_JSON to_JSON toString

first( )

Returns: mixed or EOL

Name Type Purpose
None

Returns the first element in the data structure.


last( )

Returns: mixed or ValueNotFound

Name Type Purpose
None

Returns the last element in the data structure.


swap( first, second )

Throws: InvalidArgumentType

Name Type Purpose
first int The first position
second int The second position

Swaps the position of the first and second elements.


remove( value, *func )

Returns: mixed or ValueNotFound

Name Type Purpose
value mixed The value to be removed
*func method optional: If provided, will be used for sake of comparison

Removes the first item in the list that matches value. If no such value exists, a ValueNotFound will be returned.


count( value )

Returns: int

Name Type Purpose
value mixed The value to count

Counts the number of occurences of value in the list.


filter( key, *func )

Returns: IterableList

Throws: InvalidArgumentType

Name Type Purpose
key mixed The value you want to filter by
*func method optional: If provided, will be used for sake of comparison

Returns a new IterableList containing all entires that match the key. If func is defined, this value will be passed along with the index key. Returning true will add that value to the final list.


sort( sort_or_func )

Returns: IterableList

Throws: InvalidArgumentType

Name Type Purpose
sort_or_func mixed The sort type logic to use

If sort_or_func is true, or no argument is provided, the list will be sorted in ascending order. If false, it will use a descending order. Otherwise, if a function is provided, that will determine the ordering in the list. If an invalid argument is provided, InvalidArgumentType will be thrown.


unique( *func )

Returns: IterableList

Throws: InvalidArgumentType

Name Type Purpose
*func method optional: A function to determine comparison

Returns a new IterableList containing all of the unique entires in this list. If func is provided, the comparison will be done against the results of the function. If this value is not a method, InvalidArgumentType will be thrown.


union( list, *func )

Returns: IterableList

Throws: InvalidArgumentType

Name Type Purpose
list mixed The list to combine with
*func method optional: A function to determine comparison

Returns a new IterableList combining all unique entries in this list and list. If func is provided, the comparison will be done against the results of the function. If this value is not a method, InvalidArgumentType will be thrown.


intersection( list, *func )

Returns: IterableList

Throws: InvalidArgumentType

Name Type Purpose
list mixed The list to intersect with
*func method optional: A function to determine comparison

Returns a new IterableList containing all of the entries shared with list. If func is provided, the comparison will be done against the results of the function. If this value is not a method, InvalidArgumentType will be thrown.


difference( list, *func )

Returns: IterableList

Throws: InvalidArgumentType

Name Type Purpose
list mixed The list to difference with
*func method optional: A function to determine comparison

Returns a new IterableList containing all of the entires not in the list. If func is provided, the comparison will be done against the results of the function. If this value is not a method, InvalidArgumentType will be thrown.


reverse( )

Returns: IterableList

Name Type Purpose
None

Returns a new IterableList containing all the elements of this list reversed.


shuffle( random )

Returns: IterableList

Name Type Purpose
random Randomizer optional: A randomizer to use for shuffling

Returns a new IterableList with the elements of the list randomized using a Fischer-Yates shuffle. If a randomizer is provided, that will be used instead of the GMS random functions.


find( value..., *func )

Returns: mixed or ValueNotFound

Throws: InvalidArgumentType

Name Type Purpose
value... mixed The value to find
*func method optional: The function to use to check for matches

Checks if the value exists in this list. If it does not, a ValueNotFound error will be returned. This can be check with the error_type() function. If func is provided, the return of that function will be used for comparison. If func is not a method, InvalidArgumentType will be thrown.


contains( value..., *func )

Name Type Purpose
value... mixed The value(s) to check for
*func method optional: A function to determine comparison

Returns true if the list contains all of the given values


copy( )

Returns: IterableList

Name Type Purpose
None

Returns a copy of this IterableList


is_empty( )

Returns: bool

Name Type Purpose
None

Returns if the list is empty


no_duplicates( false )

Name Type Purpose
false bool Whether or not to allow duplicates

If true, or a argument is not provided, duplicates will not be added to the list.


order( sort_or_func )

Name Type Purpose
sort_or_func mixed The sorting method to use

If sort_or_func is true, or no argument is provided, the list will be ordered in ascending fashion. If false, it will use a descending order. Otherwise, if a function is provided, that will determine the ordering in the list.


from_input( input, close )

Returns: self

Throws: InvalidArgumentType

Name Type Purpose
input InputStream An InputStream to read from.
close bool If false, the stream will not be closed after reading

Populates this structure with values from the provided input stream. By default, the stream will be closed afterwards. If close is false, however, this behavior will be overridden. If input is not an InputStream, InvalidArgumentType will be thrown.


to_output( output, close, *func )

Returns: output

Throws: InvalidArgumentType

Name Type Purpose
output Stream An stream to write to
close bool If false, the stream will not be closed after writing
*func method If provided, is used to determine what is sent to the stream

Writes this data structure to the provided output stream. By default, the stream will be closed after writing. If close is false, however, this behavior will be overridden. If output is not a Stream or func is not a method, InvalidArgumentType will be thrown.


from_array( array )

Name Type Purpose
array array An array of values

Populates this structure with values from the provided array.


to_array( *func )

Returns: array

Throws: InvalidArgumentType

Name Type Purpose
*func method If provided, is used to populate the array.

Returns this list as an array. If func is defined, the value is passed into the function and the return is written instead. If func is provided, but not a method, InvalidArgumentType is thrown.


from_JSON( JSON_string )

Returns: self

Throws: InvalidArgumentType, UnexpectedTypeMismatch

Name Type Purpose
JSON_string string The string to convert into a list

Takes the provided string and uses it to populate the list. If a string is not provided, InvalidArgumentType is thrown. If the string does not convert into an array UnexpectedTypeMismatch will be thrown.


to_JSON( )

Name Type Purpose
None

Returns this list as a JSON string


toString( )

Returns: string

Name Type Purpose
None

Converts this structure into a string and returns it.


Abstract

Jump To top

index( i )

Retrieves the value at the given index and sets the traversal pointer


next( i )

Returns the next value in the list, or EOL if the end has been reached


previous( i )

Returns the previous value in the list, or EOL if the end has been reached


push( v )

Adds the given values to the list


insert( i, v )

Inserts the value at the given index


replace( i, v )

Replaces the element at the given index with the new value


pop( i )

Pops the last value off the list, or the index if provided


clear( )

Clears the list


size( )

Returns the size of the list


Variables

Jump To top
Name Type Initial Purpose
EOL struct constant The pointer that is returned when the end of list is reached
__Dupes bool true Whether or not this IterableList will accept duplicates
__OrderedBy method undefined The function used to perform ordered insertions
Clone this wiki locally