Skip to content

Commit

Permalink
algorithms.clay: add join with no separator (concat)
Browse files Browse the repository at this point in the history
add tests for concat

remove copy-paste artefact
  • Loading branch information
galchinsky committed Oct 15, 2012
1 parent eff4d24 commit 0ed0e20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib-clay/algorithms/algorithms.clay
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ overload advancePast(pos:C, x:T) {

/// @section join

define concat(seq);

[A when Sequence?(A) and Sequence?(SequenceElementType(A))]
overload concat(a:A) {
alias T = SequenceElementType(SequenceElementType(A));
var result = Vector[T]();
for (x in a) {
pushAll(result, x);
}
return move(result);
}

define join(sep, seq);

[S, A when Sequence?(A) and Sequence?(SequenceElementType(A))
Expand Down
5 changes: 3 additions & 2 deletions test/lib-clay/algorithms/main.clay
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import algorithms.(find,endsWith?,beginsWith?,split,join);
import algorithms.(find,endsWith?,beginsWith?,split,concat,join);
import printer.(println);
import strings.*;
import sequences.*;
Expand All @@ -23,7 +23,8 @@ main() {
println("find(", s, ", ", x, ") = ", find(s, x) - begin(s));
println("split(", s, ", ", x, ") = ", split(s, x));
}


println(concat(a));
println(join("", a));
println(join(".", a));
println(join('/', a));
Expand Down
1 change: 1 addition & 0 deletions test/lib-clay/algorithms/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ split(afoobarfoo, o) = {af, , barf, , }
find(afoobarfoo, o) = 2
split(afoobarfoo, o) = {af, , barf, , }
foofoobarafoobarfoo
foofoobarafoobarfoo
.foo.foobar.afoobarfoo
/foo/foobar/afoobarfoo
{1, 2, 0, 2, 3, 0, 3, 4}
Expand Down

0 comments on commit 0ed0e20

Please sign in to comment.