Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajozwik/scalania-gist-reader
Read the files from gist by scala
https://github.com/ajozwik/scalania-gist-reader
Last synced: about 2 months ago
JSON representation
Read the files from gist by scala
- Host: GitHub
- URL: https://github.com/ajozwik/scalania-gist-reader
- Owner: ajozwik
- License: apache-2.0
- Created: 2013-11-29T07:54:28.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-06-03T12:01:37.000Z (over 10 years ago)
- Last Synced: 2023-12-15T10:00:23.036Z (about 1 year ago)
- Language: Scala
- Size: 281 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
scala-gist-reader
=================Read the files from gist - file should have only one method with requested signature.
Usage:
* Download project: git clone https://github.com/ajozwik/scalania-gist-reader.git
* Go to: cd scalania-gist-reader
* Run: sbt "project web" "run"
* Open browser: http://localhost:9000/
* Fill the fields with values:Package name (pl.japila.scalania.s99)
Object name (S99_P21)
Method singnature, (Seq[(Any, Int, Seq[Any]) => Seq[Any]])
Test name (P21Spec)
Gist numbers comma separated (7680647, 7680700)
* Submit the form
In background the playframework application is run, scalania project is downloaded from github.
From requested gists (7680647, 7680700) methods are extracted and placed to "Object name" object (S99_P21).As the last task the sbt is run in background in scalania directory with command:
sbt 'testOnly pl.japila.scalania.s99.P21Spec'
Result object and sbt output are displayed on page.
If the has similar structure as scalania, it can be used for it.
See the class with implementation (generated by tool)
object S99_P21 {
val solutions = Seq[(Any, Int, Seq[Any]) => Seq[Any]](
insertAt_7680647,
p21_7680700
)def insertAt_7680647[T](el: T, n: Int, ts: Seq[T]): Seq[T] = {
def insertToAcc: ((Seq[T], Int), T) => (Seq[T], Int) = {
(acc, current) =>
{
val (seq, index) = acc
if (index == 0) {
(current +: el +: seq, index - 1)
} else {
(current +: seq, index - 1)
}
}
}
val (l, _) = ts.foldLeft[(Seq[T], Int)]((Seq[T](), n))(insertToAcc)
l.reverse
}def p21_7680700[T](toAdd: T, position: Int, list: Seq[T]): Seq[T] = {
@tailrec
def go(n: Int, l: List[T], r: List[T]): List[T] = {
if (n == 0) l.reverse ::: toAdd :: r
else go(n - 1, r.head :: l, r.tail)
}
go(position, Nil, list.toList)
}}
Class with test (created by Jacek Laskowski):
class P21Spec extends Specification with ExamplesBlock {
"P21 solution" should {
"Insert an element at a given position into a list." in {
import S99_P21.solutions
solutions.map(s => (s"${solutionName(s)} solution", s)).foreach {
case (solution, s) =>
solution >> {
val actual = s('new, 1, Seq('a, 'b, 'c, 'd))
val expected = Seq('a, 'new, 'b, 'c, 'd)
actual === expected
}
}
}
}
}