Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save creaaa/f7a6ab2be19a48fc7f5de19b1610139e to your computer and use it in GitHub Desktop.
Save creaaa/f7a6ab2be19a48fc7f5de19b1610139e to your computer and use it in GitHub Desktop.
え、当たり前??? でもこれが Array#flatMap(_:)<SegmentOfResult : Sequence> を理解する最大にして最後のキーとなるのだ!!!
var a = [1,2,3]
a.append(contentsOf: [4,5])
print(a) // [1,2,3,4,5] // 見ての通り、[4,5]の配列がflattenされた後、追加されている!!!!!! これの理解がのちのち超大事!!!
なぜなら、`Array#flatMap(_:)<SegmentOfResult : Sequence>` は、その内部で `Array.append(contentsOf_:)` を使っているため、
`append(contentsOf_:)` を理解しておかないと、挙動を追う時ハマるから!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment