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
def drop[T](n: Int, ts: Seq[T]): Seq[T] = | |
if (n > 0) ts.grouped(n).flatMap(_.take(n - 1)).toList else Seq() |
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
def grouped[T](ts: Seq[T], n: Int) = { | |
def go(xs: Seq[T], acc: Seq[Seq[T]]): Seq[Seq[T]] = xs match { | |
case Nil => acc | |
case _ => | |
val (first, second) = xs.splitAt(n) | |
go(second, first +: acc) | |
} | |
go(ts, Seq()).reverse | |
} |
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
def encodeDirect[T](ts: Seq[T]): Seq[(Int, T)] = { | |
def encode(xs: Seq[T], acc: Seq[(Int, T)]): Seq[(Int, T)] = { | |
if (ts.isEmpty) acc | |
else { | |
val (packed, next) = ts.span(_ == ts.head) | |
encode(next, (packed.length, packed.head) +: acc) | |
} | |
} | |
encode(ts, Nil) | |
} |
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
def split[T](nr: Int, ts: Seq[T]): (Seq[T], Seq[T]) = ts.splitAt(nr) | |
def split[T](nr: Int, ts: Seq[T]): (Seq[T], Seq[T]) = (ts.take(nr), ts.drop(nr)) | |
def split[T](nr: Int, ts: Seq[T]): (Seq[T], Seq[T]) = { | |
def split[T](l: Seq[T], r: Seq[T], n: Int): (Seq[T], Seq[T]) = r match { | |
case x :: xs if n < nr => split(l :+ x, xs, n + 1) | |
case _ => (l, r) | |
} | |
split(Nil, ts, 0) |
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
object S99_P15 { | |
def duplicateN[T](n: Int, ts: Seq[T]): Seq[T] = ts match { | |
case Nil => Nil | |
case x :: xs => Seq.fill(n)(x) ++ duplicateN(n, xs) | |
} | |
} |
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
object S99_P14 { | |
def duplicate[T](as: Seq[T]): Seq[T] = | |
as.foldLeft(Seq[T]())((r, c) => r ++ Seq.fill(2)(c)) | |
} |
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
docondtable do |t| | |
t.source @users do |row| | |
t.html :class => "ladnyKlass" | |
t.columns do |c| | |
c.field(:name) do |label, data| | |
FunkyDecorator.new(data) | |
end | |
c.field :name, :label => "Provider's name" | |
c.text "Edit", :link => admin_provider_path(provider) | |
c.field => :name, :id => "provier_name" |