0

Here's what I'm trying to do:

val StringSpace = charList.reduce(_ + _ + _ + _ + " ")
val StringList = //Tokenize StringSpace with " "

but it returns missing parameter type within first line.

So how can someone actually join lists into half or quarter size in scala?

e.g: From

List ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h")

To:

List("abcd", "efgh")

2 Answers 2

3
val l = List ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h")
l.grouped(4).map(_.mkString)
Sign up to request clarification or add additional context in comments.

2 Comments

So how to make something like: List("abcd", "efgh") from "abcdefgh"?
Same thing. "abcdefgh".grouped(4).toList. A string behaves like a list of characters.
1
charList.grouped(4).map(_.mkString).toList

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.