Scalactic User Guide

Custom equality

Default equality

Constrained equality

Tolerance

Normalization

The Explicitly DSL

Or and Every

Requirements

Snapshots

TimesOnInt

TimesOnInt

The TimesOnInt trait providing an implicit conversion that adds a times method to Ints that will repeat a given side-effecting operation multiple times.

Here's an example in which a friendly greeting is printed three times:

3 times println("Hello again, world!")

Running the above code would yield this output:

Hello again, world!
Hello again, world!
Hello again, world!

If you need to repeat a block of statements multiple times, just enclose them in parentheses, like this:

2 times {
  print("Hello ")
  print("again, ")
  println("world!")
}

Running the above code would yield:

Hello again, world!
Hello again, world!

This trait enables times to be invoked on 0 and any positive integer, but attempting to invoke times on a negative integer will result in an IllegalArgumentException.

Scalactic is brought to you by Bill Venners, with contributions from several other folks. It is sponsored by Artima, Inc.
ScalaTest is free, open-source software released under the Apache 2.0 license.

Copyright © 2009-2024 Artima, Inc. All Rights Reserved.

artima