Skip to content

Instantly share code, notes, and snippets.

View dwijnand's full-sized avatar

Dale Wijnand dwijnand

View GitHub Profile
@dwijnand
dwijnand / .gitignore
Created November 7, 2018 09:21 — forked from jboner/OrderManagement.scala
Demo of an Event-driven Architecture in Akka and Scala. Show-casing Events-first DDD, Event Sourced Aggregates, Process Manager, etc.
project/
package skolems
import scala.language.implicitConversions
trait Exists[+F[_]] extends Serializable:
type A
val value: F[A]
trait Forall[+F[_]] extends Serializable:
def apply[A]: F[A]
@dwijnand
dwijnand / JNumber.1.scala
Created September 28, 2021 21:24
Which one's easier to scan?
object JNumber {
def apply(value: Int): JNumber = JNumber(value.toInt.toString)
def apply(value: Integer): JNumber = JNumber(value.toString)
def apply(value: Byte): JNumber = JNumber(value.toString)
def apply(value: Short): JNumber = JNumber(value.toString)
def apply(value: Long): JNumber = JNumber(value.toString)
def apply(value: BigInt): JNumber = JNumber(value.toString)
def apply(value: BigDecimal): JNumber = JNumber(value.toString)
def apply(value: Float): JNumber = JNumber(value.toString)
def apply(value: Double): JNumber = JNumber(value.toString)
object NumProblem:
opaque type Pos <: Int = Int
opaque type Neg <: Int = Int
object Pos { def unapply(x: Int): Option[Pos] = if (x > 0) Some(x) else None }
object Neg { def unapply(x: Int): Option[Neg] = if (x < 0) Some(x) else None }
(n: Int) match
case 0 =>
case Pos(x) =>
@dwijnand
dwijnand / fixed-strings.txt
Last active April 6, 2021 10:22
Dual strings of the same length
lo/hi
enc/dec
fst/snd
get/put/del
new/add/mod/del/(rem)
old/new
req/rsp
src/dst
usr/pwd
////////////////////////////// SCALA SYNTAX SPEC //////////////////////////////
// NEWLINE, SEMI-COLON, COMMENT
nl ::= “new line character”
semi ::= ‘;’ | nl {nl}
comment ::= ‘/*’ “any sequence of characters; nested comments are allowed” ‘*/’
| ‘//’ “any sequence of characters up to end of line”
// NUMBERS
nonZeroDigit ::= ‘1’ | … | ‘9’

The Cabal/Stack Disambiguation Guide

One of the most frequently asked Haskell beginner questions in recent years is:

"Stack or cabal?"

I will helpfully not answer this question. Instead I will hope to eliminate the confusion that many of the askers seem to have about the various different

@dwijnand
dwijnand / sbt-new
Created March 8, 2019 17:05 — forked from paulp/sbt-new
a less messy sbt new
#!/usr/bin/env bash
#
# Intercepting the output of 'sbt new' directly fails
# because it asks interactive questions so we can't process
# line by line. An apparent OSX-specific bug in egrep
# fails on lookbehind clauses so we use ag. Capturing
# the interactive output with script succeeds, but script
# uses \r\n to terminate lines so we can't match the
# filename with '.*' or we get
#
@dwijnand
dwijnand / .sbtopts
Last active March 7, 2019 22:34
Rust's From/Into ported to Conversion.scala
-sbt-version
1.2.7
@dwijnand
dwijnand / RefOrNull.scala
Created December 6, 2018 07:03
Playing with typesafe builder patterns
object RefOrNull {
type Id[A >: Null <: AnyRef] = A
type No[A >: Null <: AnyRef] = Null
def nullAs[A] = null.asInstanceOf[A]
def sideEffect[A](result: A, exprs: Any*): A = result
def set[A, B](result: A, exprs: Any*): B = result.asInstanceOf[B]
}
import RefOrNull._
final class Data[