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
Transcript
27 slides
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 次回予告
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
CloudTrail を推したい
kazzpapa3
1
160
落とし穴にハマってわかった 開発生産性を測るときに気をつけたいこと
munakata
3
460
「任されビリティ」で引き受けて「よしなりてぃ」に頼らず任せる / Accept tasks with "makasarebility" and hand them over without relying on "yoshinarily"
pauli
1
860
Linuxネットワークスタック進化の軌跡: 過去10年の歩みと最新トレンド
orimanabu
4
770
20261113_JAWS_Osaka
takuyay0ne
1
600
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
230
その修正で本当に速くなったのか? k6とOpenTelemetryで確かめる性能改善 / Performance review with k6 and OpenTelemetry
ymotongpoo
3
350
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
480
RAGの改善を速く回すための評価基盤
yosukeyoshida
6
3.4k
IP重複は"ランディングVPC"で受け止める ― PrivateLink と Transit Gatewayによるマルチテナント接続基盤の設計
hatahata021
3
250
gem install とrequire のむこうがわ
ydah
0
240
Platform Engineering をベースとした Agentic Software Factory の実践
110y
1
420
Featured
See All Featured
New Earth Scene 8
popppiees
5
2.9k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
69k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
540
Product Roadmaps are Hard
iamctodd
55
13k
Optimising Largest Contentful Paint
csswizardry
37
4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
640
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.7k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
330
HDC tutorial
michielstock
2
1k