case class Error(message: String)
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
fib 0 = 0 | |
fib 1 = 1 | |
fib 2 = 1 | |
fib n = fib (n - 1) + fib (n - 2) | |
-- Get the 100th number | |
fib 100 | |
-- But it takes too long. | |
-- You can do it with zipWith like the following line and it works much faster | |
fibs = 0 : 1 : 1 : zipWith (+) (drop 1 fibs) (drop 2 fibs) |
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
/** | |
* @author Kevin Lee | |
* @since 2016-04-09 | |
*/ | |
object StringInterpolation extends App { | |
implicit class EscapeNewLineAndDoubleQuote(val sc: StringContext) extends AnyVal { | |
def esc(args: Any*): String = { | |
val strings = sc.parts.iterator | |
val expression = args.iterator |
- Hexo: https://hexo.io/
- HubPress: https://github.com/HubPress/hubpress.io (Demo - https://www.youtube.com/watch?v=7gP3i4tHlRM)
- Hugo: https://gohugo.io/
- Jekyll: https://jekyllrb.com/
- Lektor: https://www.getlektor.com/
- Octopress: http://octopress.org/
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
let primes :: [Integer] | |
primes = sieve [2..] | |
where sieve :: [Integer] -> [Integer] | |
sieve (x : xs) = x : sieve [n | n <- xs, n `mod` x /= 0] | |
-- It works even without parameter types specified yet it is always good to have the type information | |
-- as it tells the users of the function how to use it. | |
-- It can also help you implement the function. | |
-- primes without parameter types (Uncomment it if you want to try). |
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
/** | |
* @author Kevin Lee | |
* @since 2016-01-15 | |
*/ | |
object WordCount extends App { | |
def wordCount(lines: String): Map[String, Array[Int]] = | |
lines.split('\n') | |
.map(_.trim) | |
.map(_.split("[\\s]+")) | |
.zipWithIndex |
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 cc.kevinlee.examples; | |
import java.util.Arrays; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.Optional; | |
import static cc.kevinlee.examples.KeyValPair.*; | |
/** |
NewerOlder