Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

함수형사고 4장 열심히보다는현명하게

68 views

Published on

함수형사고
4장 열심히보다는현명하게

Published in: Software
  • DOWNLOAD FULL. BOOKS INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

함수형사고 4장 열심히보다는현명하게

  1. 1. class ClassifierCacheSum { private sumCache = [:] def sumOfFactors(number) { if (!sumCache.containsKey(number)) { sumCache[number] = factorsOf(number).sum() } return sumCache[number] } }
  2. 2. print length([2+1, 3*2, 1/0, 5-4])
  3. 3. import java.util.Iterator; public class PrimeIterator implements Iterator { private int lastPrime = 1; @Override public boolean hasNext() { return true; } @Override public Integer next() { return lastPrime = Prime.nextPrimeFrom(lastPrime); } @Override public void remove() { throw new RuntimeException(“Fundamental nature of there universe exception”); } }
  4. 4. sequence(1, 2, 3, 4).filter(even); // lazily returns 2,4 sequence(1, 2).map(toString); // lazily returns "1", "2" sequence(1, 2).mapConcurrently(toString); // lazily distributes the work to background threads sequence(1, 2, 3).take(2); // lazily returns 1,2 sequence(1, 2, 3).drop(2); // lazily returns 3 sequence(1, 2, 3).tail(); // lazily returns 2,3 sequence(1, 2, 3).head(); // eagerly returns 1 sequence(1, 2, 3).reduce(sum); // eagerly return 6 sequence(1, 3, 5).find(even); // eagerly returns none() sequence(1, 2, 3).contains(2); // eagerly returns true sequence(1, 2, 3).exists(even); // eagerly return true sequence(1, 2, 3).forAll(odd); // eagerly returns false; sequence(1, 2, 3).foldLeft(0, add); // eagerly returns 6 sequence(1, 2, 3).toString(); // eagerly returns “1,2,3”
  5. 5. range(1, 4); // lazily returns 1,2,3,4 repeat("car"); // lazily returns an infinite sequence of "car"s iterate(increment, 1); // lazily returns 1,2,3 ... to infinity range(1, 4).cycle(); // lazily returns 1,2,3,4,1,2,3,4,1,2,3,4 infinitely primes(); // lazily returns every prime number fibonacci(); // lazily returns the fibonacci sequence powersOf(3); // lazily returns the powers of 3 (i.e 1,3,9,27 …)
  6. 6. def num NumberClassification { PERFECT, ABUNDANT, DEFICIENT } class NumberClasssifier { static def factorsOf(number) { (1..numbeR).findAll { i -> number %i ==0 } } static def isPerfect(number) { classify(number) == PERFECT } static def nextPerfectNumberAfter(n) { while (!isPerfect(++n)); n } static def classify(number { switch (factorsOf(number).inject(0, {i, j -> i + j})) { case { it < 2 * number }: return DEFICIENT case { it > 2 * number }: return ABUNDANT case { it == 2 * number }: return PERFECT } } }
  7. 7. def perfectNumbers(n) { prepend(n, { perfectNumbers(nextPerfectNumberAfter(n)) }) } @Test public void infinite_perfect_number_sequence() { def perfectNumbers = perfectNumbers(nextPerfectNumberAfter(1)) assertEquals([6, 28, 496], perfectNumbers.getHead(3)) }

×