Difference between revisions of "Iterable Immutable List Assignment"
Jump to navigation
Jump to search
(→Lists) |
(→Lists) |
||
Line 24: | Line 24: | ||
===cons=== | ===cons=== | ||
<nowiki>public static <E> ImmutableList<E> cons(E head, ImmutableList<E> tail)</nowiki> | <nowiki>public static <E> ImmutableList<E> cons(E head, ImmutableList<E> tail)</nowiki> | ||
+ | |||
+ | Analogous to the [http://sml-family.org/Basis/list.html SML List] [http://sml-family.org/Basis/list.html#SIG:LIST.:::TY :: constructor]. | ||
+ | |||
===brackets=== | ===brackets=== | ||
<nowiki>@SafeVarargs | <nowiki>@SafeVarargs |
Revision as of 18:48, 30 July 2019
Contents
Code To Implement
DefaultImmutableList
class: | DefaultImmutableList.java | ![]() |
methods: | head tail isEmpty iterator |
|
package: | immutable.list.assignment | |
source folder: | src/main/java |
default constructor
head and tail constructor
head
tail
isEmpty
iterator
Lists
Lists
is a class which holds a number of static methods. As we know, in the Kingdom of Nouns, Verbs must always have an escort.
The first two static methods nil
and cons
will each call a constructor of the DefaultImmutableList]] class. The third method
brackets
will use nil
and cons
to build up the desired ImmutableList.
class:
Lists.java
![Java.png](/cse425s/images/thumb/2/26/Java.png/32px-Java.png)
methods:
nil
cons
brackets
package:
immutable.list.assignment
source folder:
src/main/java
nil
public static <E> ImmutableList<E> nil()
Analogous to the SML List nil constructor.
Note: often SML programs use empty brackets []
instead of nil
.
cons
public static <E> ImmutableList<E> cons(E head, ImmutableList<E> tail)
Analogous to the SML List :: constructor.
brackets
@SafeVarargs
public static <E> ImmutableList<E> brackets(E... elements)
Test
class:
ListsTestSuite.java
![Junit.png](/cse425s/images/thumb/6/64/Junit.png/48px-Junit.png)
package:
immutable.list.assignment
source folder:
src/test/java