This file contains hidden or 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
#!/bin/sh | |
exec scala -nc "$0" "$@" | |
!# | |
import scala.io._ | |
val source = if(args.length>0) Source.fromFile(args(0)).getLines else Source.stdin.getLines | |
val pattern = """([a-zA-Z]+)-(\d+)""".r | |
source.flatMap(pattern.findFirstIn).toList.distinct.foreach(println) |
This file contains hidden or 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
cond = "false" | |
if cond then true else false end | |
=> true |
This file contains hidden or 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 match_type param | |
if param.kind_of? Integer | |
puts "it's a Integer" | |
end | |
if param.kind_of? String | |
puts "its a String" | |
end | |
if param.kind_of? Array | |
puts "its an Array" | |
end |
This file contains hidden or 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 postProcess int_list | |
int_list.map{ |i| i * 2}.each{|l| puts l} | |
end | |
list = [1,2,3,4,5] | |
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}.map{ |i|i.to_s} | |
postProcess(rs) |
This file contains hidden or 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 postProcess int_list | |
int_list.map{ |i| i - 2}.each{|l| puts l} | |
end | |
list = [1,2,3,4,5] | |
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}.map{ |i|i.to_s} | |
postProcess(rs) |
This file contains hidden or 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 postProcess int_list | |
int_list.each{|l| puts l} | |
end | |
list = [1,2,3,4,5] | |
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10}.map{ |i|i.to_s} | |
postProcess(rs) |
This file contains hidden or 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 postProcess int_list | |
int_list.each{|l| puts l} | |
end | |
list = [1,2,3,4,5] | |
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10} | |
postProcess(rs) |
This file contains hidden or 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
list = [1,2,3,4,5] | |
rs = list.map{ |i| i * 2 }.map{ |i| i + 3 }.reject{|j| j > 10} | |
rs.each{|l| puts l} |
This file contains hidden or 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 qsort[T <% Ordered[T]](list:List[T]):List[T] = { | |
list.match({ | |
case Nil => Nil; | |
case x::xs => | |
val (before,after) = xs.partition({ i => i.<(x) }); | |
qsort(before).++(qsort(after).::(x))); | |
}); | |
} | |
def qsort[T <% Ordered[T]](list:List[T]):List[T] = list match { |
This file contains hidden or 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 requestAccToken(code:String): Option[String] = if(code=="bad") None else Some("token") | |
def requestOpenId(token:String): Option[String] = Some("openId") | |
def requestUserInfo(openId:String): Option[String] = Some("notyy's account") | |
def getUser(code:String):Option[String] = requestAccToken(code) flatMap(requestOpenId) flatMap(requestUserInfo) |