Skip to content

Commit

Permalink
Use updated Symbolism typeclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jan 24, 2024
1 parent af8d26b commit 344d322
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/text/text.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ object Anticipation:
def apply(string: String): Text = string
extension (text: Text) inline def s: String = text

given add: ClosedOperator["+", Text] = _+_
given addOperator: AddOperator[Text, Text] with
type Result = Text
inline def add(left: Text, right: Text): Text = (left.s+right.s).tt

given times: Operator["*", Text, Int] with
given mulOperator: MulOperator[Text, Int] with
type Result = Text

private def recur(text: Text, n: Int, acc: Text): Text =
if n == 0 then acc else recur(text, n - 1, acc+text)

inline def apply(left: Text, right: Int): Text =
recur(left, right.max(0), "")
inline def mul(left: Text, right: Int): Text = recur(left, right.max(0), "")

given ordering: Ordering[Text] = Ordering.String.on[Text](identity)
given fromString: CommandLineParser.FromString[Text] = identity(_)
Expand Down

0 comments on commit 344d322

Please sign in to comment.