SlideShare a Scribd company logo
1 of 19
Download to read offline
psp-std
a nonstandard library
github.com/paulp/psp-std
Things I like.
• -Yno-imports -Yno-predef
• -Yno-adapted-args
• consistency
• correctness
• convenience
• no dependencies
A consciously constructed
namespace.
// This is only a sliver.
type Any = scala.Any
type GTOnce[+A] = sc.GenTraversableOnce[A]
type tailrec = scala.annotation.tailrec
type sciList[+A] = sci.List[A]
type sciMap[K, +V] = sci.Map[K, V]
type IOException = jio.IOException
Size, not lies.
/** The Size hierarchy is:
* Size
* / 
* Atomic Bounded
* / 
* Infinite Precise
*/
Julia! Lua! Over here!
final class Vindex[Base] private[std](val indexValue: Long) extends AnyVal
type Index = Vindex[Zero.type]
type Nth = Vindex[One.type]
psp> 1 to 3 apply 1
Main.scala:1004: type mismatch;
found : Int(1)
required: psp.std.all.Vdex
psp> 1 to 3 apply 1.index
res3: Int = 2
psp> 1 to 3 apply 1.nth
res4: Int = 1
Type classes, not for show
(Except for Show)
trait Eq[-A] extends Any {
def eqv(x: A, y: A): Bool
}
trait Hash[-A] extends Any {
def hash(x: A): Long
}
trait Order[-A] extends Any {
def less(x: A, y: A): Bool
}
trait Show[-A] extends Any {
def show(x: A): String
}
trait Empty[+A] extends Any {
def empty: A
}
Empty.
implicit def emptyFromCanBuild[A, R](implicit z: CanBuild[A, R]): Empty[R] = Empty(z().result)
implicit def emptyFromMakes[A, R](implicit z: Makes[A, R]): Empty[R] = Empty(elems())
implicit def emptyJavaSet[A]: Empty[jSet[A]] = Empty(new jHashSet[A])
// which provides us e.g.
psp> emptyValue[String]
res19: String = ""
psp> val x: Index = emptyValue
x: Index = -1
Empty's gonna empty
psp> view[String]().zhead
res18: String = ""
// as opposed to
psp> view[Int]().zhead
Error: could not find implicit Empty[Int]
psp> view("a", "b") zreducel (_ append _)
res20: String = ab
psp> some(5.index).zget
res21: Index = 5
psp> none[Index]().zget
res22: Index = -1
Repent, then convert
psp> view(1 -> 2).toMap[jMap]
res8: jMap[Int, Int] = {1=2}
psp> view(1 -> 2).toMap[sciMap]
res9: sciMap[Int, Int] = Map(1 -> 2)
psp> view(1 -> 2).to[sciVector]
res10: sciVector[(Int, Int)] = Vector(1 -> 2)
psp> view(1 -> 2).to[Vec]
res11: Vec[(Int, Int)] = [ 1 -> 2 ]
You may be specific.
psp> 'a' to 'g'
res12: CharRange = [a..g]
psp> ('a' to 'g').force[String]
res13: String = abcdefg
psp> ('a' to 'g').force[Vec[Char]]
res14: Vec[Char] = [ a, b, c, d, e, f, g ]
psp> ('a' to 'g').force[sciList[Char]]
res15: sciList[Char] = List(a, b, c, d, e, f, g)
psp> ('a' to 'g').to[Array]
res16: Array[Char] = [ a, b, c, d, e, f, g ]
Handful of better methods
psp> 1 to 20 splitAfter 10.size
res16: Split[Int] = [ 1, 2, 3, ... ] / [ 11, 12, 13, ... ]
// Requires a Show[Int] instance
psp> 1 to 40 grep """(d)1""".r
res17: View[Int] = [ 11, 22, 33 ]
psp> 1 to 7 splitAround 3.nth
res3: Split[Int] = [ 1, 2 ] / [ 4, 5, 6, 7 ]
// span plus one
psp> 2.andUp takeToFirst (_ % 5 == 0)
res4: View[Long] = [ 2, 3, 4, 5 ]
Predicate algebra
psp> def divBy(n: Long): ToBool[Long] = _ % n == 0L
defined function divBy
psp> 0.andUp filter divBy(7)
res24: View[Long] = [ 0, 7, 14, ... ]
psp> 0.andUp filter divBy(7) && divBy(3)
res25: View[Long] = [ 0, 21, 42, ... ]
Binary relation algebra
psp> val xs = 1 to 100 zipTail
xs: Zip[Int, Int] = [ 1 -> 2, 2 -> 3, 3 -> 4, ... ]
psp> val p1: Pred2[Int] = (_ > 8 && _ < 12)
p1: (Int, Int) => Bool = <function2>
psp> xs filter p1
res39: Zip[Int, Int] = [ 9 -> 10, 10 -> 11 ]
psp> xs filter p1 && (_ + _ == 19)
res41: Zip[Int, Int] = [ 9 -> 10 ]
Pairness awareness
psp> val xs = 1 to 100 zipTail
xs: Zip[Int, Int] = [ 1 -> 2, 2 -> 3, 3 -> 4, ... ]
psp> xs filter (_ > 8 && _ < 12)
res30: Zip[Int, Int] = [ 9 -> 10, 10 -> 11 ]
psp> (1 to 10).zipTail forall (_ + 1 == _)
res31: Boolean = true
Fitter splitter
psp> 1 to 10 span (_ <= 5)
res2: Split[Int] = [ 1, 2, 3, 4, 5 ] / [ 6, 7, 8, 9, 10 ]
psp> 1 to 10 span (_ <= 5) mapRight (_.reverseView take 2) join
res3: View[Int] = [ 1, 2, 3, 4, 5, 10, 9 ]
psp> 1 to 6 splitAfter 3.size collate
res4: View[Int] = [ 1, 4, 2, 5, 3, 6 ]
Fair trade collections
psp> val xs = scala.collection.immutable.BitSet(1, 2, 3)
xs: sciBitset = BitSet(1, 2, 3)
psp> xs o (_ map (_ + 1 toChar))
Error: could not find implicit Makes[Char, BitSet]
psp> xs o (_ map (_ + 1 toChar) map (_.toInt))
res2: sciBitset = BitSet(2, 3, 4)
To infinity... and no further
psp> def primes = mpartition(2L.andUp)(xs => _ % xs.head === 0)
defined function primes
psp> println(primes take 7 map (_ take 5))
2 4 6 8 10
3 9 15 21 27
5 25 35 55 65
7 49 77 91 119
11 121 143 187 209
13 169 221 247 299
17 289 323 391 493
Products via type class.
// Pattern matching Java map entries
psp> javaMap(1 -> 2, 3 -> 4) collect { case 1 -> n => n }
res2: View[Int] = [ 2 ]
psp> javaMap(1 -> 2, 3 -> 4) zfirst { case 3 -> n => some(n) }
res3: Option[Int] = 4
psp> javaMap(1 -> 2, 3 -> 4) zfirst { case 5 -> n => some(n) }
res4: Option[Int] = -
// And get a java map back
psp> javaMap(1 -> 2, 3 -> 4) o (_ collect { case a->b => b->a } )
res5: jMap[Int, Int] = {2=1, 4=3}
Invariant leaf collections.
// "You saved me, Capt. Invariance!"
psp> vec(1, 2, 3) :+ 4L
found : Long(4L)
required: Int
// For contrast.
scala> Vector(1, 2, 3) :+ 4L
res1: scala.collection.immutable.Vector[AnyVal] = Vector(1, 2, 3, 4)

More Related Content

What's hot

Practically Functional
Practically FunctionalPractically Functional
Practically Functionaldjspiewak
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1Hackraft
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data scienceJohn Cant
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsNicolas Hery
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Scala In The Wild
Scala In The WildScala In The Wild
Scala In The Wilddjspiewak
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldWerner Hofstra
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitTomer Gabel
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Cody Engel
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation streamRuslan Shevchenko
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java DevelopersMichael Galpin
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
Introducing: A Complete Algebra of Data
Introducing: A Complete Algebra of DataIntroducing: A Complete Algebra of Data
Introducing: A Complete Algebra of DataInside Analysis
 
What You Need to Know about Lambdas
What You Need to Know about LambdasWhat You Need to Know about Lambdas
What You Need to Know about LambdasRyan Knight
 

What's hot (19)

Practically Functional
Practically FunctionalPractically Functional
Practically Functional
 
Swift rocks! #1
Swift rocks! #1Swift rocks! #1
Swift rocks! #1
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.js
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Scala In The Wild
Scala In The WildScala In The Wild
Scala In The Wild
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Introducing: A Complete Algebra of Data
Introducing: A Complete Algebra of DataIntroducing: A Complete Algebra of Data
Introducing: A Complete Algebra of Data
 
What You Need to Know about Lambdas
What You Need to Know about LambdasWhat You Need to Know about Lambdas
What You Need to Know about Lambdas
 

Similar to Brief tour of psp-std

Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisSpbDotNet Community
 
Frsa
FrsaFrsa
Frsa_111
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingEelco Visser
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!mickey24
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In ScalaKnoldus Inc.
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate CompilersFunctional Thursday
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskellujihisa
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4Vlad Patryshev
 

Similar to Brief tour of psp-std (20)

Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 
Frsa
FrsaFrsa
Frsa
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
Extend R with Rcpp!!!
Extend R with Rcpp!!!Extend R with Rcpp!!!
Extend R with Rcpp!!!
 
Collections In Scala
Collections In ScalaCollections In Scala
Collections In Scala
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
 
Monadologie
MonadologieMonadologie
Monadologie
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4
 

More from Paul Phillips

Suffuse: a typed filesystem
Suffuse: a typed filesystemSuffuse: a typed filesystem
Suffuse: a typed filesystemPaul Phillips
 
Keynote, Lambdaconf 2017 - The Axes of Generalization
Keynote, Lambdaconf 2017 - The Axes of GeneralizationKeynote, Lambdaconf 2017 - The Axes of Generalization
Keynote, Lambdaconf 2017 - The Axes of GeneralizationPaul Phillips
 
Keynote, Lambdaconf 2016 - Equality is Hard
Keynote, Lambdaconf 2016 - Equality is HardKeynote, Lambdaconf 2016 - Equality is Hard
Keynote, Lambdaconf 2016 - Equality is HardPaul Phillips
 
Naming Things and Finding Cothings
Naming Things and Finding CothingsNaming Things and Finding Cothings
Naming Things and Finding CothingsPaul Phillips
 
Keynote, LambdaConf 2015 - Ipecac for the Ouroboros
Keynote, LambdaConf 2015 - Ipecac for the OuroborosKeynote, LambdaConf 2015 - Ipecac for the Ouroboros
Keynote, LambdaConf 2015 - Ipecac for the OuroborosPaul Phillips
 
Keynote, LambdaConf 2014 - The Silent Productivity Killer
Keynote, LambdaConf 2014 - The Silent Productivity KillerKeynote, LambdaConf 2014 - The Silent Productivity Killer
Keynote, LambdaConf 2014 - The Silent Productivity KillerPaul Phillips
 
Keynote, PNW Scala 2013
Keynote, PNW Scala 2013Keynote, PNW Scala 2013
Keynote, PNW Scala 2013Paul Phillips
 

More from Paul Phillips (7)

Suffuse: a typed filesystem
Suffuse: a typed filesystemSuffuse: a typed filesystem
Suffuse: a typed filesystem
 
Keynote, Lambdaconf 2017 - The Axes of Generalization
Keynote, Lambdaconf 2017 - The Axes of GeneralizationKeynote, Lambdaconf 2017 - The Axes of Generalization
Keynote, Lambdaconf 2017 - The Axes of Generalization
 
Keynote, Lambdaconf 2016 - Equality is Hard
Keynote, Lambdaconf 2016 - Equality is HardKeynote, Lambdaconf 2016 - Equality is Hard
Keynote, Lambdaconf 2016 - Equality is Hard
 
Naming Things and Finding Cothings
Naming Things and Finding CothingsNaming Things and Finding Cothings
Naming Things and Finding Cothings
 
Keynote, LambdaConf 2015 - Ipecac for the Ouroboros
Keynote, LambdaConf 2015 - Ipecac for the OuroborosKeynote, LambdaConf 2015 - Ipecac for the Ouroboros
Keynote, LambdaConf 2015 - Ipecac for the Ouroboros
 
Keynote, LambdaConf 2014 - The Silent Productivity Killer
Keynote, LambdaConf 2014 - The Silent Productivity KillerKeynote, LambdaConf 2014 - The Silent Productivity Killer
Keynote, LambdaConf 2014 - The Silent Productivity Killer
 
Keynote, PNW Scala 2013
Keynote, PNW Scala 2013Keynote, PNW Scala 2013
Keynote, PNW Scala 2013
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 

Brief tour of psp-std

  • 2. Things I like. • -Yno-imports -Yno-predef • -Yno-adapted-args • consistency • correctness • convenience • no dependencies
  • 3. A consciously constructed namespace. // This is only a sliver. type Any = scala.Any type GTOnce[+A] = sc.GenTraversableOnce[A] type tailrec = scala.annotation.tailrec type sciList[+A] = sci.List[A] type sciMap[K, +V] = sci.Map[K, V] type IOException = jio.IOException
  • 4. Size, not lies. /** The Size hierarchy is: * Size * / * Atomic Bounded * / * Infinite Precise */
  • 5. Julia! Lua! Over here! final class Vindex[Base] private[std](val indexValue: Long) extends AnyVal type Index = Vindex[Zero.type] type Nth = Vindex[One.type] psp> 1 to 3 apply 1 Main.scala:1004: type mismatch; found : Int(1) required: psp.std.all.Vdex psp> 1 to 3 apply 1.index res3: Int = 2 psp> 1 to 3 apply 1.nth res4: Int = 1
  • 6. Type classes, not for show (Except for Show) trait Eq[-A] extends Any { def eqv(x: A, y: A): Bool } trait Hash[-A] extends Any { def hash(x: A): Long } trait Order[-A] extends Any { def less(x: A, y: A): Bool } trait Show[-A] extends Any { def show(x: A): String } trait Empty[+A] extends Any { def empty: A }
  • 7. Empty. implicit def emptyFromCanBuild[A, R](implicit z: CanBuild[A, R]): Empty[R] = Empty(z().result) implicit def emptyFromMakes[A, R](implicit z: Makes[A, R]): Empty[R] = Empty(elems()) implicit def emptyJavaSet[A]: Empty[jSet[A]] = Empty(new jHashSet[A]) // which provides us e.g. psp> emptyValue[String] res19: String = "" psp> val x: Index = emptyValue x: Index = -1
  • 8. Empty's gonna empty psp> view[String]().zhead res18: String = "" // as opposed to psp> view[Int]().zhead Error: could not find implicit Empty[Int] psp> view("a", "b") zreducel (_ append _) res20: String = ab psp> some(5.index).zget res21: Index = 5 psp> none[Index]().zget res22: Index = -1
  • 9. Repent, then convert psp> view(1 -> 2).toMap[jMap] res8: jMap[Int, Int] = {1=2} psp> view(1 -> 2).toMap[sciMap] res9: sciMap[Int, Int] = Map(1 -> 2) psp> view(1 -> 2).to[sciVector] res10: sciVector[(Int, Int)] = Vector(1 -> 2) psp> view(1 -> 2).to[Vec] res11: Vec[(Int, Int)] = [ 1 -> 2 ]
  • 10. You may be specific. psp> 'a' to 'g' res12: CharRange = [a..g] psp> ('a' to 'g').force[String] res13: String = abcdefg psp> ('a' to 'g').force[Vec[Char]] res14: Vec[Char] = [ a, b, c, d, e, f, g ] psp> ('a' to 'g').force[sciList[Char]] res15: sciList[Char] = List(a, b, c, d, e, f, g) psp> ('a' to 'g').to[Array] res16: Array[Char] = [ a, b, c, d, e, f, g ]
  • 11. Handful of better methods psp> 1 to 20 splitAfter 10.size res16: Split[Int] = [ 1, 2, 3, ... ] / [ 11, 12, 13, ... ] // Requires a Show[Int] instance psp> 1 to 40 grep """(d)1""".r res17: View[Int] = [ 11, 22, 33 ] psp> 1 to 7 splitAround 3.nth res3: Split[Int] = [ 1, 2 ] / [ 4, 5, 6, 7 ] // span plus one psp> 2.andUp takeToFirst (_ % 5 == 0) res4: View[Long] = [ 2, 3, 4, 5 ]
  • 12. Predicate algebra psp> def divBy(n: Long): ToBool[Long] = _ % n == 0L defined function divBy psp> 0.andUp filter divBy(7) res24: View[Long] = [ 0, 7, 14, ... ] psp> 0.andUp filter divBy(7) && divBy(3) res25: View[Long] = [ 0, 21, 42, ... ]
  • 13. Binary relation algebra psp> val xs = 1 to 100 zipTail xs: Zip[Int, Int] = [ 1 -> 2, 2 -> 3, 3 -> 4, ... ] psp> val p1: Pred2[Int] = (_ > 8 && _ < 12) p1: (Int, Int) => Bool = <function2> psp> xs filter p1 res39: Zip[Int, Int] = [ 9 -> 10, 10 -> 11 ] psp> xs filter p1 && (_ + _ == 19) res41: Zip[Int, Int] = [ 9 -> 10 ]
  • 14. Pairness awareness psp> val xs = 1 to 100 zipTail xs: Zip[Int, Int] = [ 1 -> 2, 2 -> 3, 3 -> 4, ... ] psp> xs filter (_ > 8 && _ < 12) res30: Zip[Int, Int] = [ 9 -> 10, 10 -> 11 ] psp> (1 to 10).zipTail forall (_ + 1 == _) res31: Boolean = true
  • 15. Fitter splitter psp> 1 to 10 span (_ <= 5) res2: Split[Int] = [ 1, 2, 3, 4, 5 ] / [ 6, 7, 8, 9, 10 ] psp> 1 to 10 span (_ <= 5) mapRight (_.reverseView take 2) join res3: View[Int] = [ 1, 2, 3, 4, 5, 10, 9 ] psp> 1 to 6 splitAfter 3.size collate res4: View[Int] = [ 1, 4, 2, 5, 3, 6 ]
  • 16. Fair trade collections psp> val xs = scala.collection.immutable.BitSet(1, 2, 3) xs: sciBitset = BitSet(1, 2, 3) psp> xs o (_ map (_ + 1 toChar)) Error: could not find implicit Makes[Char, BitSet] psp> xs o (_ map (_ + 1 toChar) map (_.toInt)) res2: sciBitset = BitSet(2, 3, 4)
  • 17. To infinity... and no further psp> def primes = mpartition(2L.andUp)(xs => _ % xs.head === 0) defined function primes psp> println(primes take 7 map (_ take 5)) 2 4 6 8 10 3 9 15 21 27 5 25 35 55 65 7 49 77 91 119 11 121 143 187 209 13 169 221 247 299 17 289 323 391 493
  • 18. Products via type class. // Pattern matching Java map entries psp> javaMap(1 -> 2, 3 -> 4) collect { case 1 -> n => n } res2: View[Int] = [ 2 ] psp> javaMap(1 -> 2, 3 -> 4) zfirst { case 3 -> n => some(n) } res3: Option[Int] = 4 psp> javaMap(1 -> 2, 3 -> 4) zfirst { case 5 -> n => some(n) } res4: Option[Int] = - // And get a java map back psp> javaMap(1 -> 2, 3 -> 4) o (_ collect { case a->b => b->a } ) res5: jMap[Int, Int] = {2=1, 4=3}
  • 19. Invariant leaf collections. // "You saved me, Capt. Invariance!" psp> vec(1, 2, 3) :+ 4L found : Long(4L) required: Int // For contrast. scala> Vector(1, 2, 3) :+ 4L res1: scala.collection.immutable.Vector[AnyVal] = Vector(1, 2, 3, 4)