Skip to content

Instantly share code, notes, and snippets.

@kitoko552
Created April 25, 2021 02:45
Show Gist options
  • Save kitoko552/25e7bc4ce601b90975eeaa41564565e7 to your computer and use it in GitHub Desktop.
Save kitoko552/25e7bc4ce601b90975eeaa41564565e7 to your computer and use it in GitHub Desktop.
リストをseparatorで分けたリストに変換する
extension ListEx<E> on List<E> {
List<E> separated(E separator) {
return List<E>.generate(length * 2 - 1, (index) {
final idx = index ~/ 2;
return index.isEven ? this[idx] : separator;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment