Created
April 25, 2021 02:45
-
-
Save kitoko552/25e7bc4ce601b90975eeaa41564565e7 to your computer and use it in GitHub Desktop.
リストをseparatorで分けたリストに変換する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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