Last active
August 29, 2015 14:03
-
-
Save banterCZ/158e55d1f05de6fc58f2 to your computer and use it in GitHub Desktop.
We want to write a function that generates accumulators-- a function that takes a number n, and returns a function that takes another number i and returns n incremented by i. See the article Revenge of the Nerds http://www.paulgraham.com/icad.html This Scala solution comes from http://rosettacode.org/wiki/Accumulator_factory#Scala
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 AccumulatorFactory[N](n: N)(implicit num: Numeric[N]) = { | |
import num._ | |
var acc = n | |
(inc: N) => { | |
acc = acc + inc | |
acc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment