Skip to content

Instantly share code, notes, and snippets.

@es-kumagai
Created January 14, 2018 06:06
Show Gist options
  • Save es-kumagai/0f9fc59f513260e2c781646b47158808 to your computer and use it in GitHub Desktop.
Save es-kumagai/0f9fc59f513260e2c781646b47158808 to your computer and use it in GitHub Desktop.
こんな感じにしてみると、型推論のおかげで型がぜんぜん気にならなくなるから AnySequence で包んであげなくても気にならなそうね。 #CodePiece #minna_de_swift
let fibonacci = sequence(state: (current: 0, next: 1)) { state -> Int in
defer {
state = (current: state.next, next: state.current + state.next)
}
return state.current
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment