Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Introduction to Scala
Search
Yukiyan
April 21, 2020
Technology
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Scala
2020/04/21 社内LT
Scala入門
Yukiyan
April 21, 2020
More Decks by Yukiyan
See All by Yukiyan
Introduction to Scala about type parameter
yukiyan
0
180
digdagで支えるデータパイプライン / Building a data pipeline with digdag
yukiyan
1
5.9k
機械学習基盤を一人で構築するということ / Hitori ml team
yukiyan
3
3.7k
ECSのデプロイツールを試している話
yukiyan
0
2.5k
Replace a batch application to ECS
yukiyan
1
1.6k
Introduction to Docker
yukiyan
0
5.8k
Other Decks in Technology
See All in Technology
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
300
20260930_Gemma4_Hands-on
tsho
0
230
形式手法を使って仕様をコーディングしよう
mikanichinose
0
180
FinTech 1-2 : Overview of FinTech
ks91
PRO
0
150
SREでアラート疲れを 解決しよう!
kairim0
1
200
私の推しは「聞いてから進む」AIです -AI-DLCに一人でアプリを作らせた話
yama3133
1
180
購入ドメインでの課題と取り組み
ykagano
0
140
The seven pitfalls of AI (revised version)
ufried
0
270
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
150
ミイダス株式会社 テックチームのご紹介 / MIIDAS Tech Team
miidas
0
160
自律型 AI をセキュアに実装!Gemini と MIG で作る動的コード実行環境
recruitengineers
PRO
1
210
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
120
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
910
Fantastic passwords and where to find them - at NoRuKo
philnash
52
4k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Between Models and Reality
mayunak
4
480
Abbi's Birthday
coloredviolet
4
10k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
210
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Statistics for Hackers
jakevdp
799
230k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
The Curious Case for Waylosing
cassininazir
1
550
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
420
Transcript
Scala 入門 ゆきやん
教材
Scala をやる動機 データエンジニアリングをしていると Scala や Java 製のプロダクトを利用することが多い • 大規模分散処理系のプロダクトで採用事例が多い ◦
apache/spark ◦ apache/kafka ◦ apache/flink ◦ apache/beam • データ処理に便利 ◦ NULL 安全なエラーハンドリング (大規模データ処理で数時間待ってヌルポはきつい ) ◦ 型を生かした豊富なコレクションライブラリ ◦ 柔軟な非同期処理 • Java の資産を利用できる ◦ treasure-data/digdag, embulk/embulk のプラグインを Scala で書ける ◦ spotify/scio
• jenv/jenv • scalaenv/scalaenv • Language Server ◦ scalameta/metals ◦
R.I.P ENSIME IDE は必ずしも必要ではない REPL もちゃんとある (sbt console) 環境構築
基本的な文法
面白かった機能 • ケースクラス • トレイト • 高階関数 • implicit parameter
• パターンマッチ • Option, Either, Try • コレクション(for 内包表記)
ケースクラス • Value Object 使うときに役立つ
トレイト • Java のインターフェースみたいなやつ • 複数のトレイトを 1つのクラスやトレイトにミックスインできる • 直接インスタンス化できない
トレイト
高階関数
高階関数
implicit parameter メタ情報のような使うか使わないか分からん情報を、引数でひたすら引き回す手間を省ける (DBコネクションとか) 「引数の省略ができる」というメリットはあるけど、場合によっては可読性が下がるので次スライドの活用法のほ うが多用される
implicit parameter リファクタリング前
implicit parameter まずは trait でリファクタリング 要素の型で自明なのに HogeAddr 書くのが無駄
implicit parameter さらに implicit parameter で リファクタリング
型クラス(≒implicit parameter)は、うまく使うと、後付けのデータ型に対して既存のアルゴリズムを型安全に 適用するのに使うことができます。 この特徴は、特にライブラリ設計のときに重要になってきます。 ライブラリ設計時点で定義されていないデータ型に対していかにしてライブラリのアルゴリズムを適用する か、つまり、拡張性が高いように作るかというのは、なかなか難しい問題です。 簡潔に書けることを重視すると、拡張性が狭まりがちですし、拡張性が高いように作ると、デフォルトの動作で いいところを毎回書かなくてはいけなくて利用者にとって不便です。 型クラスを使ったライブラリを提供することによって、この問題をある程度緩和することができます。 皆さんも、型クラスを使って、既存の問題をより簡潔に、拡張性が高く解決できないか考えてみてください。
型クラスへの誘い · Scala研修テキスト implicit parameter
パターンマッチ
パターンマッチ
パターンマッチ
パターンマッチ
Option, Either, Try
Option, Either, Try
Option, Either, Try
Option, Either, Try
コレクション(for 内包表記) for 内包表記が便利
コレクション(for 内包表記)
• ジェネリクス ◦ class Foo[A] • 変位指定 ◦ class Foo[+A]
◦ class Foo[-A] • 型境界 ◦ class Foo[A <: B] ◦ class Foo[A >: B] • Future ◦ andThen ◦ recover, recoverWith ◦ result, ready ...etc 次回予告