Skip to content

Commit b148dec

Browse files
committed
Merge pull request #129 from knutwalker/bug/128
fix for #128 - List.init now uses the head of the sublists
2 parents ec78e55 + 642f59b commit b148dec

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎core/src/main/java/fj/data/List.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ public final List<A> init() {
11521152
List<A> ys = this;
11531153
final Buffer<A> a = empty();
11541154
while(ys.isNotEmpty() && ys.tail().isNotEmpty()) {
1155-
a.snoc(head());
1155+
a.snoc(ys.head());
11561156
ys = ys.tail();
11571157
}
11581158
return a.toList();

‎tests/src/test/scala/fj/data/CheckList.scala‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ object CheckList extends Properties("List") {
174174
property("nub") = forAll((a: List[String], b: List[String]) =>
175175
listEqual(stringEqual).eq(a append b nub, a.nub.append(b.nub).nub))
176176

177+
property("init") = forAll((a: List[String], b: String) =>
178+
listEqual(stringEqual).eq(a.snoc(b).init(), a))
179+
177180
property("join") = forAll((a: List[List[String]]) =>
178181
listEqual(stringEqual).eq(
179182
a.foldRight((a: List[String], b: List[String]) => a.append(b), nil[String]),

0 commit comments

Comments
 (0)