Skip to content

Instantly share code, notes, and snippets.

View odd's full-sized avatar
💭
Functioning

Odd Möller odd

💭
Functioning
View GitHub Profile
@DavidDudson
DavidDudson / Opt.scala
Created November 7, 2017 22:04
Allocationless Option type that converts to/from scala.Option and java.Optional
/**
* An Option class, without a few Ion's
*
* Never allocates, uses null instead.
*
* No primitives allowed.
*
* Flatmap is allowed, but nesting is not (no flatten)
*/
object Opt {
@ case class Cross[T](items: T*){
def flatMap[V](f: T => Cross[V]): Cross[(T, V)] = {
val flattened = for{
i <- items
k <- f(i).items
} yield (i, k)
Cross(flattened:_*)
}
def map[V](f: T => V): Cross[(T, V)] = {
Cross(items.map(i => i -> f(i)):_*)
@mads-hartmann
mads-hartmann / anything-dirty.sh
Created March 20, 2018 19:58
🤖 Tiny script to check if I had any dirty repos or un-pushed branches before sending my MBP to repair.
#!/bin/bash
set -euo pipefail
function is-git-repository {
[[ -d "$1/.git" ]] || (cd "$1" && git rev-parse --git-dir > /dev/null 2>&1)
}
function echo-is-dirty {
cd "$1"
if [[ ! -z $(git status -s) ]]
@SethTisue
SethTisue / scala-2.13.0-M5.md
Last active August 28, 2018 02:31
Scala 2.13.0-M5 draft release notes

Scala 2.13 is getting closer and closer!

We've been polishing the improved and simplified Scala collections library that first shipped in 2.13.0-M4. We expect the API to remain stable now, though there may still be minor changes in RC1.

M5 is our feature-freeze release for 2.13. From here forward, we’ll close existing open loops but not embark on or accept new work.

Collections changes

The major collections changes already landed in M4. See the M4 release notes for a summary.

import org.apache.ivy.core.cache.ArtifactOrigin
import sbt.*
import sbt.Keys.*
import sbt.Project.inConfig
import sbt.internal.RemoteCache.*
import sbt.internal.inc.{HashUtil, JarUtils}
import sbt.internal.librarymanagement.IvyActions.mapArtifacts
import sbt.nio.Keys.*
import sbt.plugins.SemanticdbPlugin
@johnhungerford
johnhungerford / dependency-injection.md
Last active February 22, 2025 18:15
ZIO-like dependency injection using implicit resolution

ZIO-like dependency injection using implicit resolution

Daniel Ciocîrlan recently published a video showcasing a dependency-injection (DI) approach developed by Martin Odersky that uses Scala's implicit resolution to wire dependencies automatically. (See also his reddit post.)

The basic pattern for defining services in Odersky's approach is as follows:

class Service(using Provider[(Dep1, Dep2, Dep3)])