Created
January 26, 2012 02:04
-
-
Save Villane/1680464 to your computer and use it in GitHub Desktop.
foldLeft for int arrays in Slang (there are no generics yet) (syntax highlight set to Scala because it's most similar)
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
def foldLeft(z: Int, a: [Int], f: (Int, Int) -> Int) = | |
loop(i := 0, acc := z) while i < #a do | |
(i + 1, f(acc, aᵢ)) | |
yield acc | |
def ∑(a: [Int]) = foldLeft(0, a, (x, y) -> x + y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment