Skip to content

Commit

Permalink
Change to Symbolism typeclass style
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jun 14, 2024
1 parent 3f9a7a3 commit f669b2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/core/rudiments-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ extension [ValueType](value: ValueType)
def waive: Any => ValueType = _ => value
def twin: (ValueType, ValueType) = (value, value)
def triple: (ValueType, ValueType, ValueType) = (value, value, value)

inline def iff(inline predicate: Boolean)(inline lambda: ValueType => ValueType): ValueType =
if predicate then lambda(value) else value

inline def iff(inline predicate: ValueType => Boolean)(inline lambda: ValueType => ValueType): ValueType =
if predicate(value) then lambda(value) else value

inline def is[ValueSubtype <: ValueType]: Boolean = value.isInstanceOf[ValueSubtype]

transparent inline def matchable(using Unsafe): ValueType & Matchable =
Expand Down
8 changes: 4 additions & 4 deletions src/core/rudiments.Rudiments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ object Rudiments:
given ordering: Ordering[ByteSize] = Ordering.Long.on(_.long)
given communicable[ByteSizeType <: ByteSize]: (Communicable { type Self = ByteSizeType }) = byteSize => Message(byteSize.text)

given ByteSize is Addable[ByteSize] into ByteSize as addable = _ + _
given ByteSize is Subtractable[ByteSize] into ByteSize as subtractable = _ - _
given ByteSize is Multiplicable[Int] into ByteSize as multiplicable = _*_
given ByteSize is Divisible[Int] into ByteSize as divisible = _/_
given ByteSize is Addable by ByteSize into ByteSize as addable = _ + _
given ByteSize is Subtractable by ByteSize into ByteSize as subtractable = _ - _
given ByteSize is Multiplicable by Int into ByteSize as multiplicable = _*_
given ByteSize is Divisible by Int into ByteSize as divisible = _/_

extension (left: ByteSize)
def long: Long = left
Expand Down

0 comments on commit f669b2c

Please sign in to comment.