Skip to content

Instantly share code, notes, and snippets.

@bishabosha
bishabosha / sparse-annots.scala
Last active August 1, 2026 09:26
Annotation mirror for sparse arguments to wide parameter list
// Proposal: in bishabosha/flagged, collapse all type-target annotations into
// named arguments of `@cmd`, and parameter-target annotations into named arguments of `@opt`
// sparse encoding of Annotation:
// type-level encoding of `@opt(help = "foo", positional = true)`.
// It is assumed that if a runtime value is needed, then consumer has access to Defaults Mirror and
// scala.deriving.Mirror.Of[opt] to compute argument list.
// compiletime only consumers can traverse the sparse arguments (and assume defaults for rest)
type X = Ann[
/* type = */ opt,
@bishabosha
bishabosha / TupleOf.scala
Last active July 3, 2026 13:40
TupleOf redesign June 2026
package scalax
object TupleOf {
import Inner.*
type Bound[T0] = T0 match {
case SomeTupleOf[?, arg] => arg
}
type Shape[T0] = T0 match {
case SomeTupleOf[t, ?] => t
}
@bishabosha
bishabosha / patch-codex-mcp.sc
Last active June 15, 2026 12:38
Patch MCP server in local Codex settings
#! /usr/bin/env -S scala shebang
//> using dep "com.indoorvivants::toml:0.3.0"
//> using toolkit default
case class Settings(
local: Boolean = true,
`mcp-server`: String = "scala-metals",
url: Option[String] = None
)
@bishabosha
bishabosha / 1. A brief for direct-style Validation.
Last active May 2, 2026 16:57
Prototype for a Validation DSL to accumulate errors
This prototype was developed on 7th April 2024.
The brief is to design a "clean-room" Scala validation API (based on the
boundary/break mechanism) that can help users transform raw data into a
rich and type-safe aggregate value (such as a Form, or other "data model").
The idea is a scope that provides a capability to accumulate multiple errors, i.e.
so that component parts that are independent can be tested "at the same time",
rather than abort early on the first error.
@bishabosha
bishabosha / nattyv2.scala
Created April 21, 2026 19:45
Natural Numbers Folding Cases
//> using scala 3.8.4
//> using platform native
import scalanative.unsafe.*
@main def hello =
Zone:
// Defining constant arrays in Scala Native
// Here we try to allocate a 1567891 byte array
@bishabosha
bishabosha / bench.scala
Created February 25, 2026 16:18
NamedTuple toSeqMap benchmark
//> using scala "3.8.2"
//> using jmh
// run with `scala --power bench.scala`
package bench
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.BenchmarkMode
import org.openjdk.jmh.annotations.Level
@bishabosha
bishabosha / VarArgsBuilder.scala
Last active November 23, 2025 15:44
Benchmark varargs builder changes in scala 3
package runtimeStrawman
import scala.collection.immutable.ArraySeq
import scala.reflect.ClassTag
sealed abstract class VarArgsBuilder[T]:
def add(elem: T): this.type
def addSeq(elems: Seq[T]): this.type
def addArray(elems: Array[T]): this.type
def result(): Seq[T]
@bishabosha
bishabosha / string-interpolators.scala
Created November 3, 2025 14:58
Useful Scala string interpolators
extension (ctx: StringContext)
/** Regex pattern */
transparent inline def rg(s: Any*): scala.util.matching.Regex =
ctx.raw(s*).r
/** Whitespace-Separated list*/
transparent inline def ws(s: Any*): IndexedSeq[String] =
ctx.s(s*).split(raw"\s+").filter(_.nonEmpty).toIndexedSeq
@bishabosha
bishabosha / zed_tasks.json
Created October 10, 2025 18:16
Zed configuration to extract main class fqn for Scala
[
{
"label": "Scala run",
"command": "scala",
"args": [
"run",
"-M",
"$(if [ -z \"${ZED_CUSTOM_scala_package_name:}\" ] ; then echo \"$ZED_CUSTOM_scala_main_function_name\"; else echo \"${ZED_CUSTOM_scala_package_name:}.$ZED_CUSTOM_scala_main_function_name\"; fi)",
"$ZED_WORKTREE_ROOT"
],
@bishabosha
bishabosha / Scala.plist
Created September 25, 2025 09:46
Scala BBEdit Module with metals LSP
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<!-- Enhanced Scala Codeless Language Module for BBEdit
Supports advanced syntax highlighting, folding, function indexing, and Metals LSP -->
<dict>
<!-- You must identify the plist as a CLM: -->