SlideShare a Scribd company logo
ゼロから始めるScalaプロジェクト
 
 
 
 
 
2
 
 
 
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
 
4
 
 
scala
  sbt	about
 
 
5
 
 sbt	new	scala/hello-world.g8	
 
 
 
 cd	sbt-example sbt	
 
  sbt	run
6
 
 run	
 
 console	
 println("Hello")	
 
Main.main(null)	
  :paste	
 :quit
7
 
 
8
9
sbt-example/	
	├	build.sbt	
	├	project/	
	│	├	build.properties	
	│	└	plugins.sbt	
	├	src/	
	│	├	main/	
	│	│	└	scala/	
	│	│			└	Main.scala	
	│	└	test/	
	│			└	scala/	
	│					└	MainSpec.scala	
	└	target/
10
 
 
 
 
11
 
 
 
 
 
 
 
 
 
 
 
  reload
12
 
 libraryDependencies	++=	Seq(	
		"org.scala-sbt"	%%	"io"	%	"1.0.0",	
		"org.json4s"	%%	"json4s-jackson"	%	"3.5.2",	
		"org.scalatest"	%%	"scalatest"	%	"3.0.1"	%	Test)	
 
 reload	
 console	
 import	sbt.io.IO	
 
13
 
 
 
 
 
 
 
 
 
 
 
 
14
 
 
 
 
 
 
 def	fizzBuzz(n:	Int):	Unit	=	???	
 
 
15
object	Main	
		extends	App	{	???	}	
object	Main	{	
		def	main(…):	Unit	=	
				{	???	}	
}
def	fizzBuzz(n:	Int):	Unit	=	
		for	{i	<-	1	to	n}	{	
				i	match	{	
						case	x	if	x	%	15	==	0	=>	println("FizzBuzz")	
						case	x	if	x	%	3	==	0	=>	println("Fizz")	
						case	x	if	x	%	5	==	0	=>	println("Buzz")	
						case	x	=>	println(x)	
				}	
		}	
	
fizzBuzz(15)
16
 
 
 
 
 
 
 
 
 
17
val	pw	=	new	
java.io.PrintWriter("sample.json")	
pw.print(scala.io.Source.fromURL("h
ttps://goo.gl/KbGKi7").mkString)	
pw.flush();	pw.close()
 
 def	readFile(fileName:	String)	
				:	String	=	???	
 
 import	sbt.io.IO	
 IO.read	
 java.io.File
18
import	sbt.io.IO	
import	java.io.File	
	
def	readFile(fileName:	String):	String	=		
		IO.read(new	File(fileName))
19
 
 
 def	parseIntArrayJSON(jsonString:	String)	
				:	List[Int]	=	???	
 
 import	org.json4s._	
 import	org.json4s.jackson.JsonMethods	
 JsonMethods.parse	
 
 
 toInt	
20
import	org.json4s._	
import	org.json4s.jackson.JsonMethods._	
	
def	parseIntArrayJSON(jsonString:	String)	
				:	List[Int]	=	{	
		val	json	=	parse(jsonString)	
		for	{	
				JArray(array)	<-	json	
				JInt(x)	<-	array	
		}	yield	x.toInt	
}
21
 
 def	toFizzBuzz(ints:	List[Int])	
				:	List[String]	=	???	
 
 
22
def	toFizzBuzz(ints:	List[Int])	
				:	List[String]	=	
		for	{i	<-	ints}	
				yield	i	match	{	
						case	x	if	x	%	15	==	0	=>	"FizzBuzz"	
						case	x	if	x	%	3	==	0	=>	"Fizz"	
						case	x	if	x	%	5	==	0	=>	"Buzz"	
						case	x	=>	x.toString	
				}
23
def	toFizzBuzz(ints:	List[Int])	
				:	List[String]	=	
		ints.map(i	=>	
				i	match	{	
						case	x	if	x	%	15	==	0	=>	"FizzBuzz"	
						case	x	if	x	%	3	==	0	=>	"Fizz"	
						case	x	if	x	%	5	==	0	=>	"Buzz"	
						case	x	=>	x.toString	
				})
24
def	toFizzBuzz(ints:	List[Int])	
				:	List[String]	=	
		ints.map(i	=>	
				i	match	{	
						case	x	if	x	%	15	==	0	=>	"FizzBuzz"	
						case	x	if	x	%	3	==	0	=>	"Fizz"	
						case	x	if	x	%	5	==	0	=>	"Buzz"	
						case	x	=>	x.toString	
				})
25
def	toFizzBuzz(ints:	Seq[Int]):	Seq[String]	=	
		ints.map	{	
				case	x	if	x	%	15	==	0	=>	"FizzBuzz"	
				case	x	if	x	%	3	==	0	=>	"Fizz"	
				case	x	if	x	%	5	==	0	=>	"Buzz"	
				case	x	=>	x.toString	
		}
26
 
 def	toJSONFormat(list:	List[String])	
				:	String	=	???	
 
 import	org.json4s.JsonDSL._	
 render/compact
27
import	org.json4s.JsonDSL._	
import	org.json4s.jackson.JsonMethods._	
	
def	toJSONFormat(list:	List[String]):	String	=	
		compact(render(list))
28
 
 def	writeFile(fileName:	String,	
				contents:	String):	Unit	=	???	
 
 import	sbt.io.IO	
 IO.write	
 java.io.File	
29
import	sbt.io.IO	
	
def	writeFile(fileName:	String,	
														contents:	String):	Unit	=		
		IO.write(new	File(fileName),	contents)
30
 
 
 
 
 
 
 import	org.scalatest._	
 class	MainSpec	extends	FlatSpec	{	...	}	
 "foo"	should	"bar"	in	{	???	}	
 assert	
31
class MainSpec extends FlatSpec {!
"FizzBuzzed sample.json" should!
"have the same elements as answer.json" in {!
val sampleString = IO.read(new File("sample.json"))!
val sampleJSON = JsonMethods.parse(sampleString)!
val sample = for {!
JArray(arr) <- sampleJSON!
JInt(x) <- arr!
} yield x.toInt!
val fizzBuzzedSample = Main.toFizzBuzz(sample)!
val answerString = IO.read(new File("answer.json"))!
val answerJSON = JsonMethods.parse(answerString)!
val answer = for {!
JArray(arr) <- answerJSON!
JString(x) <- arr!
} yield x!
assert(!
fizzBuzzedSample.sameElements(answer))!
}!
}
import java.io.File!
import org.json4s._!
import org.json4s.jackson.JsonMethods!
import org.scalatest._!
import sbt.io.IO!
32
 
 
 addSbtPlugin("org.xerial.sbt"	%	"sbt-pack"	%	"0.9.0")	
 sbt	pack	
 
 
 
 
 
33

More Related Content

PDF
No dark magic - Byte code engineering in the real world
PPTX
OWASP AppSecCali 2015 - Marshalling Pickles
PPTX
Es6 hackathon
PDF
Jakarta Commons - Don't re-invent the wheel
ODP
Introduccion a Jasmin
PPT
Mastering Java ByteCode
PDF
Your code is not a string
PDF
FalsyValues. Dmitry Soshnikov - ECMAScript 6
No dark magic - Byte code engineering in the real world
OWASP AppSecCali 2015 - Marshalling Pickles
Es6 hackathon
Jakarta Commons - Don't re-invent the wheel
Introduccion a Jasmin
Mastering Java ByteCode
Your code is not a string
FalsyValues. Dmitry Soshnikov - ECMAScript 6

What's hot (20)

PDF
Rust ⇋ JavaScript
PDF
PHP unserialization vulnerabilities: What are we missing?
PDF
Introduction aux Macros
PDF
Building fast interpreters in Rust
ODP
ES6 PPT FOR 2016
PDF
greenDAO
PDF
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
PDF
New methods for exploiting ORM injections in Java applications
PDF
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
PDF
Singletons in PHP - Why they are bad and how you can eliminate them from your...
KEY
Php Code Audits (PHP UK 2010)
PPTX
Don't Be Afraid of Abstract Syntax Trees
PPTX
Introduction to Ecmascript - ES6
PPTX
Java 8 briefing
PDF
JavaScript on the GPU
PDF
LetSwift RxSwift 시작하기
PDF
async/await Revisited
PPTX
Beyond java8
KEY
Scala for scripting
PDF
Why Every Tester Should Learn Ruby
Rust ⇋ JavaScript
PHP unserialization vulnerabilities: What are we missing?
Introduction aux Macros
Building fast interpreters in Rust
ES6 PPT FOR 2016
greenDAO
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
New methods for exploiting ORM injections in Java applications
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Php Code Audits (PHP UK 2010)
Don't Be Afraid of Abstract Syntax Trees
Introduction to Ecmascript - ES6
Java 8 briefing
JavaScript on the GPU
LetSwift RxSwift 시작하기
async/await Revisited
Beyond java8
Scala for scripting
Why Every Tester Should Learn Ruby
Ad

Similar to ゼロから始めるScalaプロジェクト (11)

PPTX
Sbt baby steps
PDF
Real world scala
PPTX
Getting started with sbt
PPTX
SBT by Aform Research, Saulius Valatka
PDF
Programming Android Application in Scala.
ODP
How to start using Scala
PPTX
SBT Concepts, part 2
PPT
An introduction to maven gradle and sbt
TXT
5 subtitles (text) for tutorial working on the programming assignments (8-47)
Sbt baby steps
Real world scala
Getting started with sbt
SBT by Aform Research, Saulius Valatka
Programming Android Application in Scala.
How to start using Scala
SBT Concepts, part 2
An introduction to maven gradle and sbt
5 subtitles (text) for tutorial working on the programming assignments (8-47)
Ad

More from Ryuichi ITO (7)

PPTX
scala.collection 再入門 (改)
PDF
ゼロから始めるScala文法
PDF
Internship final report@Treasure Data Inc.
PPTX
OUCC LT会2
PPTX
サクサクアンドロイド
PPTX
getstartedc#_2
PPTX
getstartedc#_1
scala.collection 再入門 (改)
ゼロから始めるScala文法
Internship final report@Treasure Data Inc.
OUCC LT会2
サクサクアンドロイド
getstartedc#_2
getstartedc#_1

Recently uploaded (20)

PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
ai tools demonstartion for schools and inter college
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Digital Strategies for Manufacturing Companies
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administration Chapter 2
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Essential Infomation Tech presentation.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Transform Your Business with a Software ERP System
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
ai tools demonstartion for schools and inter college
Reimagine Home Health with the Power of Agentic AI​
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Design an Analysis of Algorithms II-SECS-1021-03
Digital Strategies for Manufacturing Companies
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administration Chapter 2
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms I-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Essential Infomation Tech presentation.pptx
How Creative Agencies Leverage Project Management Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Introduction to Artificial Intelligence
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Transform Your Business with a Software ERP System

ゼロから始めるScalaプロジェクト