Created
May 7, 2021 04:40
-
-
Save CheolhoJeon/ebb476fe543a4f86ac0a19d0ac067e7b to your computer and use it in GitHub Desktop.
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
package chap4.FolddingLists | |
import atomictest.eq | |
fun main() { | |
val list = listOf('a', 'b', 'c', 'd') | |
list.fold("*") { acc, elem -> | |
"($acc) + $elem" | |
} eq "((((*) + a) + b) + c) + d" | |
list.foldRight("*") { elem, acc -> | |
"$elem + ($acc)" | |
} eq "a + (b + (c + (d + (*))))" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment