Clean up (#64)
* [readme] use valid haskell example * [tree] Immediately return this expression instead of assigning it to the temporary variable "treeList". * [tree] Use normal defensive copying for array fields
This commit is contained in:
parent
7f5657e8e8
commit
b2fe2f4557
3 changed files with 8 additions and 12 deletions
|
@ -34,11 +34,12 @@
|
|||
if you try and use them together. e.g.:
|
||||
|
||||
#+BEGIN_SRC haskell
|
||||
type PhoneNumber = String
|
||||
type Name = String
|
||||
type PhoneBook = [(Name,PhoneNumber)]
|
||||
newtype PhoneNumber = PhoneNumber String
|
||||
newtype Name = Name String
|
||||
newtype PhoneBookEntry = PhoneBookEntry (Name, PhoneNumber)
|
||||
newtype PhoneBook = PhoneBook [PhoneBookEntry]
|
||||
#+END_SRC
|
||||
|
||||
|
||||
In Java we don't have the ability to have that true alias, so TypeAlias is
|
||||
more of a type-wrapper. It's as close as I could get to a Haskell type alias
|
||||
in Java.
|
||||
|
|
|
@ -50,7 +50,7 @@ class GeneralisedTree<T> implements Tree<T>, TreeMapper<T> {
|
|||
*/
|
||||
GeneralisedTree(final T item, final Collection<Tree<T>> subTrees) {
|
||||
this.item = item;
|
||||
this.subTrees = Collections.unmodifiableList(new ArrayList<>(subTrees));
|
||||
this.subTrees = new ArrayList<>(subTrees);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,6 +77,6 @@ class GeneralisedTree<T> implements Tree<T>, TreeMapper<T> {
|
|||
*/
|
||||
@Override
|
||||
public List<Tree<T>> subTrees() {
|
||||
return subTrees;
|
||||
return new ArrayList<>(subTrees);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A mutable {@link Tree}.
|
||||
|
@ -126,12 +125,8 @@ class MutableTree<T> implements Tree<T>, TreeMapper<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Tree<T>> subTrees() {
|
||||
final Stream<MutableTree<T>> mutableTreeStream = mySubTrees.stream();
|
||||
final Stream<Tree<T>> treeStream = mutableTreeStream.map(Tree.class::cast);
|
||||
final List<Tree<T>> treeList = treeStream.collect(Collectors.toList());
|
||||
return treeList;
|
||||
return new ArrayList<>(mySubTrees);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue