CanBuildFrom
TraversableLikeの暗黙パラメータにおったやつ
こんなん
//A -> a private implicit class Converter(l: Traversable[A]) { //https://gamaspecial.hatenablog.com/entry/2019/10/11/165653 def to: Seq[a] = l.map( r => a( value = r.value ) )(collection.breakOut) //<-こいつなんやねん } def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { def builder = { // extracted to keep method size under 35 bytes, so that it can be JIT-inlined val b = bf(repr)
参考にする https://blog.tiqwab.com/2018/12/28/rip-can-build-from.html
がんばってよむ
/** A base trait for builder factories. * * @tparam From the type of the underlying collection that requests * a builder to be created. * @tparam Elem the element type of the collection to be created. * @tparam To the type of the collection to be created. * * @see [[scala.collection.mutable.Builder]] * @author Martin Odersky * @author Adriaan Moors * @since 2.8 */ @implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") trait CanBuildFrom[-From, -Elem, +To] { /** Creates a new builder on request of a collection. * @param from the collection requesting the builder to be created. * @return a builder for collections of type `To` with element type `Elem`. * The collections framework usually arranges things so * that the created builder will build the same kind of collection * as `from`. */ def apply(from: From): Builder[Elem, To] /** Creates a new builder from scratch. * * @return a builder for collections of type `To` with element type `Elem`. * @see scala.collection.breakOut */ def apply(): Builder[Elem, To] }