Julia One Liners to Impress Your Friends

(1 to 10) map { _ * 2 }
map(x->2x, 1:10)
(1 to 1000).reduceLeft( _ + _ )
(1 to 1000).sum
reduce(+, 1:1000)
sum(1:1000)
val wordList = List("scala", "akka", "play framework", "sbt", "typesafe")
val tweet = "This is an example tweet talking about scala and sbt."
(wordList.foldLeft(false)( _ || tweet.contains(_) ))
wordList.exists(tweet.contains)
wordlist = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."
any(word->contains(tweet, word), wordlist)
val fileText = io.Source.fromFile("data.txt").mkString
filetext = readstring(“data.txt”)`
val fileLines = io.Source.fromFile("data.txt").getLines.toList
filelines = open(readlines, "data.txt")
(1 to 4).map { i => "Happy Birthday " + (if (i == 3) "dear NAME" else "to You") }.foreach { println }
foreach(println, map(i->"Happy Birthday " * (i == 3 ? "dear NAME" : "to You"), 1:4))
lines = map(1:4) do i 
"Happy Birthday " *
if i == 3 "dear NAME" else "to You" end
end
print(join(lines, "\n"))
val (passed, failed) = List(49, 58, 76, 82, 88, 90) partition ( _ > 60 )
grades = [49, 58, 76, 82, 88, 90]
passed = filter(grade->grade > 60, grades)
failed = filter(grade->grade <= 60, grades)
function partition{T}(p, xs::Vector{T})
as = T[]
bs = T[]
for x in xs
if p(x)
push!(as, x)
else
push!(bs, x)
end
end
(as, bs)
end
passed, failed = partition(grade->grade > 60, grades)
val results = XML.load("http://search.twitter.com/search.atom?&q=scala")
List(14, 35, -7, 46, 98).reduceLeft ( _ min _ )
List(14, 35, -7, 46, 98).min
List(14, 35, -7, 46, 98).reduceLeft ( _ max _ )
List(14, 35, -7, 46, 98).max
reduce(min, [14, 35, -7, 46, 98])
min(14, 35, -7, 46, 98)
reduce(max, [14, 35, -7, 46, 98])
max(14, 35, -7, 46, 98)
val result = dataList.par.map( line => processItem(line) )
result = pmap(process_item, data_list)
pmap(x->x^2, 1:10)
(n: Int) => (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store