Skip to content

Instantly share code, notes, and snippets.

extension [A, B] (t: Tuple2[A, B])
inline infix def ||>[C](inline f: (A, B) => C): C =
f(t._1, t._2)
extension [T] (t: T)
infix def |>[B](f: T => B): B =
f(t)
def add(a:Int, b: Int):String = (a + b).toString
open System
open FreeRedis
// Define a function to construct a message to print
let from whom = sprintf "from %s" whom
let inline (|>!) x sideEffect =
do sideEffect x
x
import scala.jdk.CollectionConverters._
import scala.util.chaining._
case class Myforable[A](v: List[A]):
def foreach[T](f: A => T): Unit = v.foreach(f)
def map[T](f: A => T): Myforable[T] = Myforable(v.map(f))
def flatMap[T](f: A => Myforable[T]): Myforable[T] =
val list: List[T] = v.map(f).map(_.v).flatten
sealed trait Metric(val name: String, val description: String)
case class Counter(override val name: String,
override val description: String,
value: Double
) extends Metric(name, description)
trait ToText[T <: Metric]:
def toText(t: T): String
import scala.language.{dynamics, unsafeNulls}
class DynamicBO(m: Map[String, Any]) extends Selectable, Dynamic {
def selectDynamic(name: String): Any = m.getOrElse(name, null)
}
type User = DynamicBO {val name: String; val age: Int}
abstract class BaseDynamic extends Dynamic
extension[T] (t: T)
infix inline def |>[B](block: T => B): B = block(t)
infix inline def <|(block: T => Unit): T =
block(t)
t
enum Opt[+T]:
case Empty
case Box(t: T)
private def print_type_tree(clazz: Class[?], level: Int = 0): Unit =
if clazz != null then
println((" " * level) + clazz)
val nextLevel = level + 2
clazz.getInterfaces.foreach(it => print_type_tree(it, nextLevel))
print_type_tree(clazz.getSuperclass, nextLevel)
@itang
itang / dmake.ts
Last active February 22, 2021 12:11
import {
desc as description,
run,
sh,
shCapture,
task,
} from "https://deno.land/x/[email protected]/mod.ts";
interface DevEnvTask {
name: string;
import java.util.{Date as JDate}
import scala.io.Source as S
trait JsonOps[T] {
def stringify(t: T): String
extension (x:T) def toJSON(): String = stringify(x)
}
given intJsonOps: JsonOps[Int] with {
package example
import scala.scalajs.js
class C(val a: String, val b: Boolean, val c: Int) extends js.Object
object C {
def apply(a: String, b: Boolean, c: Int): C = new C(a, b, c)
}