scala中map是将每一条输入通过给定的函数映射为一个新对象,flatMap相比较于map可以理解为map+flatten
flatten:遍历每一个可以遍历的的元素并且返回一个集合(该集合不包含内置集合)
/** Converts this $coll of traversable collections into
* a $coll formed by the elements of these traversable
* collections.
*
* @tparam B the type of the elements of each traversable collection.
* @param asTraversable an implicit conversion which asserts that the element
* type of this $coll is a `GenTraversable`.
* @return a new $coll resulting from concatenating all element ${coll}s.
*
* @usecase def flatten[B]: $Coll[B]
*
* @inheritdoc
*
* The resulting collection's type will be guided by the
* static type of $coll. For example:
*
* {
{
{
* val xs = List(
* Set(1, 2, 3),
* Set(1, 2, 3)
*