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,9 +34,10 @@
|
||||||
if you try and use them together. e.g.:
|
if you try and use them together. e.g.:
|
||||||
|
|
||||||
#+BEGIN_SRC haskell
|
#+BEGIN_SRC haskell
|
||||||
type PhoneNumber = String
|
newtype PhoneNumber = PhoneNumber String
|
||||||
type Name = String
|
newtype Name = Name String
|
||||||
type PhoneBook = [(Name,PhoneNumber)]
|
newtype PhoneBookEntry = PhoneBookEntry (Name, PhoneNumber)
|
||||||
|
newtype PhoneBook = PhoneBook [PhoneBookEntry]
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
In Java we don't have the ability to have that true alias, so TypeAlias is
|
In Java we don't have the ability to have that true alias, so TypeAlias is
|
||||||
|
|
|
@ -50,7 +50,7 @@ class GeneralisedTree<T> implements Tree<T>, TreeMapper<T> {
|
||||||
*/
|
*/
|
||||||
GeneralisedTree(final T item, final Collection<Tree<T>> subTrees) {
|
GeneralisedTree(final T item, final Collection<Tree<T>> subTrees) {
|
||||||
this.item = item;
|
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
|
@Override
|
||||||
public List<Tree<T>> subTrees() {
|
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.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mutable {@link Tree}.
|
* A mutable {@link Tree}.
|
||||||
|
@ -126,12 +125,8 @@ class MutableTree<T> implements Tree<T>, TreeMapper<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public List<Tree<T>> subTrees() {
|
public List<Tree<T>> subTrees() {
|
||||||
final Stream<MutableTree<T>> mutableTreeStream = mySubTrees.stream();
|
return new ArrayList<>(mySubTrees);
|
||||||
final Stream<Tree<T>> treeStream = mutableTreeStream.map(Tree.class::cast);
|
|
||||||
final List<Tree<T>> treeList = treeStream.collect(Collectors.toList());
|
|
||||||
return treeList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue