SlideShare a Scribd company logo
class ClassifierCacheSum {
private sumCache = [:]
def sumOfFactors(number) {
if (!sumCache.containsKey(number)) {
sumCache[number] = factorsOf(number).sum()
}
return sumCache[number]
}
}
print length([2+1, 3*2, 1/0, 5-4])
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”); }
}
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”
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 …)
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
}
}
}
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))
}
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게
함수형사고 4장 열심히보다는현명하게

More Related Content

What's hot

Php 5.6
Php 5.6Php 5.6
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
takezoe
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
GroovyPuzzlers
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
Anaya Zafar
 
LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)
LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)
LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)
Sylvain Hallé
 
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
AAKASH KUMAR
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
Sylvain Hallé
 
Android taipei 20160225 淺談closure
Android taipei 20160225   淺談closureAndroid taipei 20160225   淺談closure
Android taipei 20160225 淺談closure
Gance Zhi-Hong Zhu (朱智鴻)
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
Romain Francois
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
jonbodner
 
dplyr
dplyrdplyr
Being functional in PHP
Being functional in PHPBeing functional in PHP
Being functional in PHP
David de Boer
 
Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings
Sylvain Hallé
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
DEVTYPE
 
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
Sylvain Hallé
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
Zayen Chagra
 
Fun with functions
Fun with functionsFun with functions
Fun with functions
Frank Müller
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
Kent Ohashi
 

What's hot (20)

Jquery callbacks
Jquery callbacksJquery callbacks
Jquery callbacks
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
 
The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)The groovy puzzlers (as Presented at Gr8Conf US 2014)
The groovy puzzlers (as Presented at Gr8Conf US 2014)
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)
LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)
LabPal: Repeatable Computer Experiments Made Easy (ACM Workshop Talk)
 
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
 
When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)When RV Meets CEP (RV 2016 Tutorial)
When RV Meets CEP (RV 2016 Tutorial)
 
Android taipei 20160225 淺談closure
Android taipei 20160225   淺談closureAndroid taipei 20160225   淺談closure
Android taipei 20160225 淺談closure
 
Rcpp11 genentech
Rcpp11 genentechRcpp11 genentech
Rcpp11 genentech
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
dplyr
dplyrdplyr
dplyr
 
Being functional in PHP
Being functional in PHPBeing functional in PHP
Being functional in PHP
 
Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings Activity Recognition Through Complex Event Processing: First Findings
Activity Recognition Through Complex Event Processing: First Findings
 
4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка4. Обработка ошибок, исключения, отладка
4. Обработка ошибок, исключения, отладка
 
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)BeepBeep 3: A declarative event stream query engine (EDOC 2015)
BeepBeep 3: A declarative event stream query engine (EDOC 2015)
 
Lec1
Lec1Lec1
Lec1
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
 
Fun with functions
Fun with functionsFun with functions
Fun with functions
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 

Viewers also liked

HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증
박 민규
 
HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템
박 민규
 
HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅
박 민규
 
HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시
박 민규
 
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
박 민규
 
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
박 민규
 
실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화
박 민규
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
박 민규
 
HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리
박 민규
 
Two sides of the world
Two sides of the worldTwo sides of the world
Two sides of the world
Chandan Dubey
 
It`s Satya Paul for mandira once again!
It`s Satya Paul for mandira once again!It`s Satya Paul for mandira once again!
It`s Satya Paul for mandira once again!
Satya Paul
 
ภาคผนวก
ภาคผนวกภาคผนวก
ภาคผนวกeinscream
 
Ամանորյա ֆոտոպատում
Ամանորյա ֆոտոպատումԱմանորյա ֆոտոպատում
Ամանորյա ֆոտոպատում
tatevabrahamyan
 
Non-EMC SAN Products Data Reference Manual
Non-EMC SAN Products Data Reference Manual   Non-EMC SAN Products Data Reference Manual
Non-EMC SAN Products Data Reference Manual
EMC
 
Geography turkey
Geography turkeyGeography turkey
Geography turkey
pasha5163
 
Social influences specification
Social influences specificationSocial influences specification
Social influences specification
butcher665
 
Praesentation smart value_nk
Praesentation smart value_nkPraesentation smart value_nk
Praesentation smart value_nk
sitefuchs
 

Viewers also liked (20)

HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증HTTP 완벽가이드- 12 기본 인증
HTTP 완벽가이드- 12 기본 인증
 
HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템HTTP 완벽가이드- 19장 배포시스템
HTTP 완벽가이드- 19장 배포시스템
 
Pig
PigPig
Pig
 
HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅HTTP 완벽가이드- 18 웹 호스팅
HTTP 완벽가이드- 18 웹 호스팅
 
HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시HTTP 완벽가이드 7장 캐시
HTTP 완벽가이드 7장 캐시
 
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
실무로 배우는 시스템 성능 최적화 - 프로세스의 메모리 구조 2
 
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
HTTP 완벽가이드 10장 http2.0, 11장_클라이언트식별과쿠키
 
실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화실무로 배우는 시스템 성능 최적화
실무로 배우는 시스템 성능 최적화
 
HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증HTTP 완벽가이드- 13 다이제스트 인증
HTTP 완벽가이드- 13 다이제스트 인증
 
HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리HTTP 완벽가이드 4장 커넥션관리
HTTP 완벽가이드 4장 커넥션관리
 
Two sides of the world
Two sides of the worldTwo sides of the world
Two sides of the world
 
It`s Satya Paul for mandira once again!
It`s Satya Paul for mandira once again!It`s Satya Paul for mandira once again!
It`s Satya Paul for mandira once again!
 
jngjnbvg
jngjnbvgjngjnbvg
jngjnbvg
 
ภาคผนวก
ภาคผนวกภาคผนวก
ภาคผนวก
 
Ամանորյա ֆոտոպատում
Ամանորյա ֆոտոպատումԱմանորյա ֆոտոպատում
Ամանորյա ֆոտոպատում
 
Non-EMC SAN Products Data Reference Manual
Non-EMC SAN Products Data Reference Manual   Non-EMC SAN Products Data Reference Manual
Non-EMC SAN Products Data Reference Manual
 
Valentine & Kebartas
Valentine & KebartasValentine & Kebartas
Valentine & Kebartas
 
Geography turkey
Geography turkeyGeography turkey
Geography turkey
 
Social influences specification
Social influences specificationSocial influences specification
Social influences specification
 
Praesentation smart value_nk
Praesentation smart value_nkPraesentation smart value_nk
Praesentation smart value_nk
 

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

ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
Kazuhiro Sera
 
Javascript
JavascriptJavascript
Javascript
Vlad Ifrim
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
Simone Federici
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
hesher
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
Sunghyouk Bae
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Bruno Scopelliti
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
Visual Engineering
 
Rust-lang
Rust-langRust-lang
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
Eduard Tomàs
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
Baruch Sadogursky
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 
Kotlin Collections
Kotlin CollectionsKotlin Collections
Kotlin Collections
Halil Özcan
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
msemenistyi
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
Baruch Sadogursky
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
Francis Johny
 

Similar to 함수형사고 4장 열심히보다는현명하게 (20)

ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
 
Javascript
JavascriptJavascript
Javascript
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
Kotlin Collections
Kotlin CollectionsKotlin Collections
Kotlin Collections
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 

Recently uploaded

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 

Recently uploaded (20)

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 

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

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. class ClassifierCacheSum { private sumCache = [:] def sumOfFactors(number) { if (!sumCache.containsKey(number)) { sumCache[number] = factorsOf(number).sum() } return sumCache[number] } }
  • 6.
  • 7.
  • 8.
  • 10. 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”); } }
  • 11. 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”
  • 12. 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 …)
  • 13. 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 } } }
  • 14. 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)) }