Skip to content

Instantly share code, notes, and snippets.

View olegkovalenko's full-sized avatar

Oleg Kovalenko olegkovalenko

  • Evolution Gaming
View GitHub Profile
@jrudolph
jrudolph / SimpleQuicClientMain.scala
Last active February 20, 2020 16:45
"Simple" "Http/3" "client"
import java.math.BigInteger
import java.net.DatagramPacket
import java.net.DatagramSocket
import java.net.InetAddress
import java.security.KeyPairGenerator
import java.security.MessageDigest
import java.security.SecureRandom
import java.security.interfaces.ECPrivateKey
import java.security.interfaces.ECPublicKey
import java.security.spec.ECPoint
@mpilquist
mpilquist / big3.scala
Last active September 25, 2019 00:40
Example encoding of Functor / Applicative / Monad using dotty 0.15
/* Example of encoding Functor/Applicative/Monad from cats with Dotty 0.15 features.
* Derived in part from Cats -- see https://github.com/typelevel/cats/blob/master/COPYING for full license & copyright.
*/
package structures
import scala.annotation._
trait Functor[F[_]] {
def (fa: F[A]) map[A, B](f: A => B): F[B]
def (fa: F[A]) as[A, B](b: B): F[B] =
@jdegoes
jdegoes / fpmax.scala
Created July 13, 2018 03:18
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@jastice
jastice / integrations-bsp-intellij-bloop.md
Last active June 28, 2019 11:48 — forked from jvican/integrations-bsp-intellij-bloop.md
Instructions to try the BSP IntelliJ-Bloop integration out.

Installation instructions

  1. Install bloop 1.0.0-M11 by following the Bloop installation instructions. Then, make sure you start up the bloop server on the background and to generate the configuration files by running bloopInstall in your build tool.
  2. Install IntelliJ 2018.2 EAP and then enable the nightly version of the Scala Plugin by opening Preferences | Languages & Frameworks | Scala | Updates tab and selecting the Nightly plugin update channel: intellij-eap
  3. check for updates and download the Scala plugin Nightly release.
  4. Reboot IntelliJ. The Scala plugin should now have version 2018.2.277 or higher (check in Preferences | Plugins)
  5. Open the "Find Action" search box (usual hotkey Shift+Ctrl+A or shift+cmd+A) and search for "bsp". The search box will show the full action name: "Enable experime
@malcolmgreaves
malcolmgreaves / write_to_temp_file.scala
Last active August 26, 2019 15:40
Write a string to a temporary file in Scala.
import java.io.{ File, PrintWriter }
/** Creates a temporary file, writes the input string to the file, and the file handle.
*
* NOTE: This funciton uses the createTempFile function from the File class. The prefix and
* suffix must be at least 3 characters long, otherwise this function throws an
* IllegalArgumentException.
*/
def writeToTempFile(contents: String,
prefix: Option[String] = None,

Revisiting Tagless Final Interpreters

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@Icelandjack
Icelandjack / Constraints.org
Last active April 2, 2024 20:22
Type Classes and Constraints

Reddit discussion.

Disclaimer 1: Type classes are great but they are not the right tool for every job. Enjoy some balance and balance to your balance.

Disclaimer 2: I should tidy this up but probably won’t.

Disclaimer 3: Yeah called it, better to be realistic.

Type classes are a language of their own, this is an attempt to document features and give a name to them.

@smarter
smarter / gadt.md
Last active March 6, 2024 23:33
GADTs in Scala

Generalized Algebraic Data Types in Scala

Basic GADTs

Here's an ADT which is not a GADT, in Haskell:

data Expr = IntExpr Int | BoolExpr Bool

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString