Skip to content

Commit

Permalink
scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rmgk committed Mar 2, 2024
1 parent 3359129 commit bde85b9
Show file tree
Hide file tree
Showing 84 changed files with 1,217 additions and 1,201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ trait ReactiveMirrorBundle extends FullMVTurnReflectionBundle {
type State[V] = self.State[V]
override type Value = Nothing
override protected[reactives] val state = this
override def toString: String = s"Mirror${info.description}"
override val host: FullMVEngine = null
override def toString: String = s"Mirror${info.description}"
override val host: FullMVEngine = null
override def incrementFrame(txn: FullMVTurn): FramingBranchResult[FullMVTurn, Derived.of[State]] = {
FullMVUtil.myAwait(txn.addRemoteBranch(TurnPhase.Framing), timeout)
reflectionProxy.asyncIncrementFrame(txn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ object AeadHelper {
*/
def encrypt(message: String, associatedData: String, key: Uint8Array): Try[Uint8Array] = Try {
val nonce: Uint8Array = generateRandomNonce()
val cipherText = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(message, associatedData, null, nonce, key, undefined)
val cipherText =
sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(message, associatedData, null, nonce, key, undefined)
concatenateArrays(nonce, cipherText)
}

Expand All @@ -109,7 +110,8 @@ object AeadHelper {
*/
def encrypt(message: Uint8Array, associatedData: Uint8Array, key: Uint8Array): Try[Uint8Array] = Try {
val nonce: Uint8Array = generateRandomNonce()
val cipherText = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(message, associatedData, null, nonce, key, undefined)
val cipherText =
sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(message, associatedData, null, nonce, key, undefined)
concatenateArrays(nonce, cipherText)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class AeadTest extends munit.ScalaCheckSuite {

implicit def executionContext: ExecutionContext = TestExecutionContext.executionContext

test("AeadHelper.ready should work"){
test("AeadHelper.ready should work") {
AeadHelper.ready().map(_ => ())(executionContext)
}

test("decrypt should successfully decrypt generated byte array and empty associated data"){
test("decrypt should successfully decrypt generated byte array and empty associated data") {
val aead = AeadKey.generateKey.aeadPrimitive
forAll(byteArrayGen) { (message: ByteArray) =>
val ciphertext = aead.encrypt(message, Generators.emptyByteArray).get
Expand All @@ -35,7 +35,7 @@ class AeadTest extends munit.ScalaCheckSuite {
}
}

test( "should work for empty message") {
test("should work for empty message") {
val aead = AeadKey.generateKey.aeadPrimitive

assertEquals("", aead.decrypt(aead.encrypt("", "").get, "").get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class JsArrayBufferMessageBuffer(val inner: ArrayBuffer) extends MessageBuffer {
}

object MesageBufferExtensions {
extension (mb: MessageBuffer) def asArrayBuffer: ArrayBuffer =
mb match
case buf: JsArrayBufferMessageBuffer => buf.inner
case other => other.asArray.toTypedArray.buffer
extension (mb: MessageBuffer)
def asArrayBuffer: ArrayBuffer =
mb match
case buf: JsArrayBufferMessageBuffer => buf.inner
case other => other.asArray.toTypedArray.buffer
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object Example {
val selfId = Random.nextLong()

Async[Ctx] {
val msg = broadcast.receive.bind
val msg = broadcast.receive.bind
val communication: BroadcastCommunication = msg.convert
Async[Ctx].bind:
Async[Ctx].fromCallback:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def connect(host: String, port: Int): Async[Any, TCPConnection] = Async.fromCall
Async.handler.fail(exception)
}


class TCPConnection(socket: Socket) extends InChan with OutChan {

// socket streams
Expand Down Expand Up @@ -87,6 +86,3 @@ class TCPConnection(socket: Socket) extends InChan with OutChan {
}

}



Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ class DeltaAddWinsLastWriterWinsMap[K, V](

def put(key: K, value: V): Unit =
mutate(
DeltaAddWinsMap.deltaMutate[K, Map[Dot, (
V,
LastWriterWins[Uid]
)]](
DeltaAddWinsMap.deltaMutate[K, Map[
Dot,
(
V,
LastWriterWins[Uid]
)
]](
key,
Map.empty,
delta =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import reactives.core.AdmissionTicket
import reactives.default.*
import reactives.default.global.State as BundleState


trait Shape extends Serializable {
val changed: Event[Any]
val centerX: Signal[Int]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ object MLTest {
val backwardsPropagate = Signal(true)
val groundTruth = Signal { math.pow(2 * input.value - 3.0, 2) }
val learn_rate = Signal { 0.4 }
val res = diff_app(input, backwardsPropagate, groundTruth, learn_rate)
val res = diff_app(input, backwardsPropagate, groundTruth, learn_rate)
println(res.now)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ case class Point[@specialized(Int, Double) T: Numeric](x: T, y: T) extends Shape
def *(d: T) = Point(x * d, y * d)
def /(d: Double) = Point(x.toDouble / d, y.toDouble / d)

def euclidian = math.sqrt((x * x + y * y).toDouble)
def normalize = if (x == 0 && y == 0) this else this / euclidian
infix def distance(p: Point[T]) = (p - this).euclidian
def directionTo(p: Point[T]) = (p - this).normalize
def euclidian = math.sqrt((x * x + y * y).toDouble)
def normalize = if (x == 0 && y == 0) this else this / euclidian
infix def distance(p: Point[T]) = (p - this).euclidian
def directionTo(p: Point[T]) = (p - this).normalize
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Main extends App {
store,
(store.itemAdded map { (x: RSSItem) => // #EF
(x.srcChannel map (_.title) getOrElse "<unknown>") + ": " + x.title
}) `hold` "", // #IF
}) `hold` "", // #IF
Signal.dynamic { // #SIG
val itemCount = (store.channels.value map { case (_, items) => items.value.size }).sum
"Channels: " + store.channels.value.size + " Items: " + itemCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import reactives.default._
class Fetcher(val urls: Signal[Set[URL]]) {
lazy val rssFetched: Event[(NodeSeq, URL)] = fetch.after map { (_: (URL, NodeSeq)).swap } // #EVT //#EF
lazy val state: Signal[String] = // #SIG
((fetch.before map { (_: Any) => "Started fetching" }) || // #EF //#EF
((fetch.before map { (_: Any) => "Started fetching" }) || // #EF //#EF
(fetch.after map { (_: Any) => "Finished fetching" })) `hold` "" // #EF //#IF

val firstFetchInitiated = collection.mutable.Set.empty[URL]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import universe.Animal._

import reactives.default.*


class Carnivore(implicit world: World) extends Animal {

private val sleepy = energy map { _ < Animal.SleepThreshold }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ object HTML {
def providers(exdat: FbdcExampleData) = {
div(
h1("make a request"),

).render.reattach(
exdat.providers.map { prov =>
prov.observeRemoveMap.entries.map { (id, provided) =>
Expand All @@ -114,7 +113,6 @@ object HTML {
}
}
),

).render.reattach(exdat.latestFortune.map(f => p(f.map(_.result).getOrElse("")).render))

def northwindBox(exdat: FbdcExampleData, id: Uid) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object SyncMessage {

case class AppointmentMessage(state: CalendarState, target: String) extends SyncMessage
case class RaftMessage(state: RaftState[Token]) extends SyncMessage
case class WantMessage(state: Dotted[ReplicatedSet[Token]]) extends SyncMessage
case class FreeMessage(state: Dotted[ReplicatedSet[Token]]) extends SyncMessage
case class WantMessage(state: Dotted[ReplicatedSet[Token]]) extends SyncMessage
case class FreeMessage(state: Dotted[ReplicatedSet[Token]]) extends SyncMessage

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package replication.fbdc
import de.rmgk.script.{process, runOutput}
import rdts.datatypes.LastWriterWins


object Fortunes {

def enableConditional(exampleData: FbdcExampleData) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.util.Properties
import scala.collection.mutable.ListBuffer
import scala.util.chaining.scalaUtilChainingOps


object Northwind {

val dbProperties = new Properties().tap(_.setProperty("immutable", "1"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ object Voting {

}


case class Exclusive[T: Lattice: Bottom](token: Token, value: T) {
def transform(f: T => T)(using ReplicaId) =
if token.isOwner then f(value) else Bottom.empty
}


/** totally not incredibly inefficient */
case class Causal[T: Lattice: HasDots: Bottom](deltas: Set[Dotted[T]]) {
def value: T =
val causalPrefix = deltas.map(_.context).reduceOption(_ union _).map(_.causalPrefix).getOrElse(Dots.empty)
deltas.filter(delta => delta.context <= causalPrefix).reduceOption(Dotted.lattice.merge).map(_.data).getOrElse(Bottom.empty)
deltas.filter(delta => delta.context <= causalPrefix).reduceOption(Dotted.lattice.merge).map(_.data).getOrElse(
Bottom.empty
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AWSetTest extends munit.ScalaCheckSuite {
implicit val IntCodec: JsonValueCodec[Int] = JsonCodecMaker.make
property("add") {
forAll { (set: AntiEntropyContainer[ReplicatedSet[Int]], e: Int) =>
given ReplicaId = set.replicaID
given ReplicaId = set.replicaID
val added: AntiEntropyContainer[ReplicatedSet[Int]] = set.add(e)

val elems = added.elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ORMapTest extends munit.ScalaCheckSuite {
given rdts.syntax.ReplicaId = rdts.syntax.ReplicaId.predefined("test")
given Bottom[Int] with
def empty = Int.MinValue
forAll{ (entries: List[Int]) =>
val orMap = entries.foldLeft(Dotted(ObserveRemoveMap.empty[Int, Int])) {(curr, elem) => curr.update(elem, elem)}
orMap.entries.foreach{(k, v) =>
forAll { (entries: List[Int]) =>
val orMap = entries.foldLeft(Dotted(ObserveRemoveMap.empty[Int, Int])) { (curr, elem) => curr.update(elem, elem) }
orMap.entries.foreach { (k, v) =>
assert(orMap.contains(k))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ class Focus[Inner: DottedLattice, Outer](dm: DataManager[Outer])(extract: Outer
type RespValue = Option[LastWriterWins[Res]]
given Ordering[VectorClock] = VectorClock.vectorClockTotalOrdering

given HasDots[RespValue] = HasDots.noDots
given HasDots[RespValue] = HasDots.noDots
given DottedLattice[RespValue] = Dotted.lattice


case class State(
requests: CausalQueue[Req],
responses: ObserveRemoveMap[String, RespValue],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import reactives.core.{CreationTicket, Derived, DynamicTicket, ReInfo, ReadAs}
import reactives.default.*
import reactives.default.global.State as BundleState


case class DeltaWithState[Delta, DState](delta: Seq[Delta], state: DState)

class DeltaStateReactive[Delta, Combined](
Expand Down Expand Up @@ -42,7 +41,8 @@ object DeltaStateReactive {
applyDelta: (DState, Delta) => DState,
handlers: Seq[(DynamicTicket[BundleState], DState) => Delta]
)(implicit name: ReInfo, creationTicket: CreationTicket[BundleState]): DeltaStateReactive[Delta, DState] =
creationTicket.scope.create(Set(deltaInput), DeltaWithState(List.empty[Delta], init), needsReevaluation = false)(state =>
new DeltaStateReactive(state, deltaInput, applyDelta, handlers, name)
creationTicket.scope.create(Set(deltaInput), DeltaWithState(List.empty[Delta], init), needsReevaluation = false)(
state =>
new DeltaStateReactive(state, deltaInput, applyDelta, handlers, name)
)
}
14 changes: 9 additions & 5 deletions Modules/Example Todolist/src/main/scala/todo/TaskData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ case class TaskRef(id: String) {
lazy val cached: TaskRefData = TaskReferences.lookupOrCreateTaskRef(id, None)

def task: Signal[DeltaBuffer[Dotted[LastWriterWins[Option[TaskData]]]]] = cached.task
def tag: LI = cached.tag
def tag: LI = cached.tag
def removed: Event[String] = cached.removed
}

Expand Down Expand Up @@ -88,7 +88,12 @@ class TaskReferences(toggleAll: Event[dom.Event], storePrefix: String) {
else DeltaBuffer(Dotted(LastWriterWins.now(task)))

val edittext: Event.CBR[dom.Event, dom.html.Input] = Event.fromCallback {
input(`class` := "edit", `type` := "text", onchange := Event.handle[dom.Event], onblur := Event.handle[dom.Event]).render
input(
`class` := "edit",
`type` := "text",
onchange := Event.handle[dom.Event],
onblur := Event.handle[dom.Event]
).render
}

val edittextStr = edittext.event.map { (e: dom.Event) =>
Expand Down Expand Up @@ -125,7 +130,7 @@ class TaskReferences(toggleAll: Event[dom.Event], storePrefix: String) {
val removeButton =
Event.fromCallback(button(`class` := "destroy", onclick := Event.handle))

val editInput = edittext.data.reattach(Signal{ value := taskData.value.desc})
val editInput = edittext.data.reattach(Signal { value := taskData.value.desc })
editDiv.event.observe { _ =>
setTimeout(0) { editInput.focus() }; ()
}
Expand All @@ -143,7 +148,7 @@ class TaskReferences(toggleAll: Event[dom.Event], storePrefix: String) {
removeButton.data
),
editInput
).render.reattach(Signal{
).render.reattach(Signal {
`class` := (if editingV.value then "editing" else "no-editing")
})

Expand All @@ -158,7 +163,6 @@ given RangeSplice[Modifier] with {
case elem: dom.Element => value.applyTo(elem)
}


implicit def optionAttrValue[T](implicit ev: AttrValue[T]): AttrValue[Option[T]] =
new AttrValue[Option[T]] {
override def apply(t: Element, a: Attr, v: Option[T]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import reactives.core.StaticTicket
import reactives.default.*
import reactives.default.global.State as BundleState


type CEventsFromEvents[T <: Tuple] <: Tuple = T match
case EmptyTuple => EmptyTuple
case Event[t] *: ts => CEvent[t] *: CEventsFromEvents[ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.{ReadWriteLock, ReentrantReadWriteLock}
import reactives.default.global.State as BundleState


@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
Expand All @@ -19,8 +18,8 @@ import reactives.default.global.State as BundleState
@State(Scope.Benchmark)
class SingleVar {

var engine: Interface = scala.compiletime.uninitialized
final lazy val engineT = engine
var engine: Interface = scala.compiletime.uninitialized
final lazy val engineT = engine
implicit def scheduler: Scheduler[engineT.global.State] = engineT.global.scheduler

var source: engineT.Var[Boolean] = scala.compiletime.uninitialized
Expand All @@ -32,7 +31,8 @@ class SingleVar {
engine = engineParam.engine
current = false
source = engineT.Var(current)
if (engineParam.engine.global.scheduler == reactives.scheduler.LevelbasedVariants.unmanaged) lock = new ReentrantReadWriteLock()
if (engineParam.engine.global.scheduler == reactives.scheduler.LevelbasedVariants.unmanaged)
lock = new ReentrantReadWriteLock()
}

@Benchmark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MapBenchmarkWithInsert {
var addEvent: Evt[Int] = scala.compiletime.uninitialized
var mappedSeq: Signal[Seq[Int]] = scala.compiletime.uninitialized

var reactSeq: IncSeq[Int] = scala.compiletime.uninitialized
var reactSeq: IncSeq[Int] = scala.compiletime.uninitialized
var reactMappedSeq: ReactiveDeltaSeq[Int] = scala.compiletime.uninitialized

@Setup(Level.Invocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package benchmarks.incremental
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole


import reactives.default.*
import reactives.extra.incremental.*

Expand All @@ -26,7 +25,7 @@ class MapBenchmarkWithRemove {
var removeEvent: Evt[Int] = scala.compiletime.uninitialized
var mappedSeq: Signal[Seq[Int]] = scala.compiletime.uninitialized

var reactSeq: IncSeq[Int] = scala.compiletime.uninitialized
var reactSeq: IncSeq[Int] = scala.compiletime.uninitialized
var reactMappedSeq: ReactiveDeltaSeq[Int] = scala.compiletime.uninitialized

@Setup(Level.Invocation)
Expand Down
Loading

0 comments on commit bde85b9

Please sign in to comment.