Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Final implicit class #96

Merged
merged 3 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object FSWatcher {
/**
* File System Watcher Extensions
*/
implicit class FSWatcherExtensions(val watcher: FSWatcher) extends AnyVal {
implicit final class FSWatcherExtensions(val watcher: FSWatcher) extends AnyVal {

/**
* Emitted when something changes in a watched directory or file. See more details in fs.watch().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object ReadStream {
/**
* Read Stream Events
*/
implicit class ReadStreamEvents(val stream: ReadStream) extends AnyVal {
implicit final class ReadStreamEvents(val stream: ReadStream) extends AnyVal {

/**
* Emitted when the ReadStream's underlying file descriptor has been closed using the fs.close() method.
Expand All @@ -83,7 +83,7 @@ object ReadStream {
/**
* Read Stream Extensions
*/
implicit class ReadStreamExtensions(val stream: ReadStream) extends AnyVal {
implicit final class ReadStreamExtensions(val stream: ReadStream) extends AnyVal {

@inline
def closeFuture: Future[Unit] = promiseCallback1[Unit](stream.close)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object WriteStream {
/**
* Write Stream Events
*/
implicit class WriteStreamEvents(val stream: WriteStream) extends AnyVal {
implicit final class WriteStreamEvents(val stream: WriteStream) extends AnyVal {

/**
* Emitted when the WriteStream's underlying file descriptor has been closed using the fs.close() method.
Expand All @@ -80,7 +80,7 @@ object WriteStream {
/**
* Write Stream Extensions
*/
implicit class WriteStreamExtensions(val stream: WriteStream) extends AnyVal {
implicit final class WriteStreamExtensions(val stream: WriteStream) extends AnyVal {

@inline
def closeFuture: Future[Unit] = promiseCallback1[Unit](stream.close)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package object fs {
* File System Extensions
* @param fs the given [[Fs file system]] instance
*/
final implicit class FsExtensions(private val fs: Fs) extends AnyVal {
implicit final class FsExtensions(private val fs: Fs) extends AnyVal {
@inline
def accessFuture(path: Buffer | String): Future[Unit] = {
promiseWithError0[FileIOError](fs.access(path, _))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Server {
* Server Events
* @param server the given [[Server]]
*/
final implicit class ServerEvents(val server: Server) extends AnyVal {
implicit final class ServerEvents(val server: Server) extends AnyVal {

/**
* Emitted each time a request with an HTTP Expect: 100-continue is received. If this event is not listened for,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package object https {
/**
* Https Extensions
*/
final implicit class HttpExtensions(val https: Https) extends AnyVal {
implicit final class HttpExtensions(val https: Https) extends AnyVal {

/**
* Like http.get() but for HTTPS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package object net {
* net.Server Events
* @param server the given [[Server server]]
*/
implicit class ServerEvents(val server: Server) extends AnyVal {
implicit final class ServerEvents(val server: Server) extends AnyVal {

/**
* Emitted when a new connection is made. socket is an instance of net.Socket.
Expand Down Expand Up @@ -46,7 +46,7 @@ package object net {
* net.Socket Extensions
* @param socket the given [[Socket socket]]
*/
implicit class SocketExtensions(val socket: Socket) extends AnyVal {
implicit final class SocketExtensions(val socket: Socket) extends AnyVal {

/////////////////////////////////////////////////////////////////////////////////
// Futures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object Interface {
* Readline Interface Events
* @param readline the given [[Interface Readline Interface]]
*/
implicit class ReadlineEvents(val readline: Interface) extends AnyVal {
implicit final class ReadlineEvents(val readline: Interface) extends AnyVal {

/**
* Emitted when close() is called. Also emitted when the input stream receives its 'end' event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object REPLServer {
* REPL Server Extensions
* @param server the given [[REPLServer REPL Server]]
*/
final implicit class REPLServerExtensions[T <: REPLServer](val server: T) extends AnyVal {
implicit final class REPLServerExtensions[T <: REPLServer](val server: T) extends AnyVal {

/**
* Emitted when the user exits the REPL in any of the defined ways. Namely, typing .exit at the repl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package object repl {
* REPL Server events
* @param server the given [[REPLServer instance]]
*/
final implicit class REPLServerEvents(val server: REPLServer) extends AnyVal {
implicit final class REPLServerEvents(val server: REPLServer) extends AnyVal {

@inline
def contextAs[T]: T = server.context.asInstanceOf[T]
Expand Down Expand Up @@ -47,7 +47,7 @@ package object repl {
* <li>NODE_REPL_MODE</li>
* </ul>
*/
final implicit class EnvironmentVariableOptions(private val env: process.Environment) extends AnyVal {
implicit final class EnvironmentVariableOptions(private val env: process.Environment) extends AnyVal {

/**
* When a valid path is given, persistent REPL history will be saved to the specified file rather
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Immediate {
* Immediate Enrichment
* @param immediate the given [[Immediate immediate]] handle
*/
implicit class ImmediateEnrichment(val immediate: Immediate) extends AnyVal {
implicit final class ImmediateEnrichment(val immediate: Immediate) extends AnyVal {

@inline
def clear(): Unit = clearImmediate(immediate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Interval {
* Interval Enrichment
* @param handle the given [[Interval interval]] handle
*/
implicit class IntervalEnrichment(val handle: Interval) extends AnyVal {
implicit final class IntervalEnrichment(val handle: Interval) extends AnyVal {

@inline
def clear(): Unit = clearInterval(handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Timeout {
* Timeout Enrichment
* @param handle the given [[Timeout timeout]] handle
*/
implicit class TimeoutEnrichment(val handle: Timeout) extends AnyVal {
implicit final class TimeoutEnrichment(val handle: Timeout) extends AnyVal {

@inline
def clear(): Unit = clearTimeout(handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package object tty {
* Write Stream Events
* @param stream the given [[WriteStream stream]]
*/
implicit class WriteStreamEvents(val stream: WriteStream) extends AnyVal {
implicit final class WriteStreamEvents(val stream: WriteStream) extends AnyVal {

/**
* The 'resize' event is emitted whenever either of the writeStream.columns or writeStream.rows properties have
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object JsCollection {
* JavaScript Collection Enrichment
* @param collection the given [[JsCollection collection]]
*/
implicit class JsCollectionEnrichment[T](val collection: JsCollection[T]) extends AnyVal {
implicit final class JsCollectionEnrichment[T](val collection: JsCollection[T]) extends AnyVal {

@inline
def get(index: Int): Option[T] = Option(collection(index))
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/io/scalajs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package object scalajs {
* JSON Enrichment
* @param json the given [[JSON]] object
*/
implicit class JSONEnrichment(val json: JSON) extends AnyVal {
implicit final class JSONEnrichment(val json: JSON) extends AnyVal {

@inline
def parseAs[T](text: String): T = json.parse(text).asInstanceOf[T]
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/io/scalajs/util/DateHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object DateHelper {
* Date Enrichment
* @param date0 the given [[js.Date date]]
*/
implicit class DateEnrichment(val date0: js.Date) extends AnyVal {
implicit final class DateEnrichment(private val date0: js.Date) extends AnyVal {

@inline
def +(duration: Duration) = new js.Date(date0.getTime() + duration.toMillis)
Expand Down Expand Up @@ -41,7 +41,7 @@ object DateHelper {
* Duration Enrichment
* @param duration the given [[Duration duration]]
*/
implicit class DurationEnrichment(val duration: Duration) extends AnyVal {
implicit final class DurationEnrichment(private val duration: Duration) extends AnyVal {

@inline
def +(date: js.Date) = new js.Date(date.getTime() + duration.toMillis)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/io/scalajs/util/JSONHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object JSONHelper {
* JSON Conversions
* @param value the given JavaScript value
*/
implicit class JSONConversionsToJson[T <: js.Any](val value: T) extends AnyVal {
implicit final class JSONConversionsToJson[T <: js.Any](val value: T) extends AnyVal {

@inline
def toJson: String = JSON.stringify(value)
Expand All @@ -27,7 +27,7 @@ object JSONHelper {
* JSON Conversions
* @param text the given text string
*/
implicit class JSONConversionFromJson(val text: String) extends AnyVal {
implicit final class JSONConversionFromJson(val text: String) extends AnyVal {

@inline
def fromJson[T <: js.Any]: T = JSON.parse(text).asInstanceOf[T]
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/io/scalajs/util/JsUnderOrHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object JsUnderOrHelper {
* UndefOr Extensions
* @param valueA the given [[js.UndefOr value]]
*/
implicit class UndefOrExtensions[T](val valueA: js.UndefOr[T]) extends AnyVal {
implicit final class UndefOrExtensions[T](private val valueA: js.UndefOr[T]) extends AnyVal {

@inline def ?==(valueB: js.UndefOr[T]): Boolean = valueA.exists(valueB.contains)

Expand Down Expand Up @@ -40,7 +40,7 @@ object JsUnderOrHelper {
* UndefOr Boolean Extensions
* @param value the given [[js.UndefOr value]]
*/
implicit class UndefOrBoolExtensions(val value: js.UndefOr[Boolean]) extends AnyVal {
implicit final class UndefOrBoolExtensions(private val value: js.UndefOr[Boolean]) extends AnyVal {

@inline
def isTrue: Boolean = value.flat.contains(true)
Expand All @@ -51,7 +51,7 @@ object JsUnderOrHelper {
* UndefOr Double Extensions
* @param value the given [[js.UndefOr value]]
*/
implicit class UndefOrDoubleExtensions(val value: js.UndefOr[Double]) extends AnyVal {
implicit final class UndefOrDoubleExtensions(val value: js.UndefOr[Double]) extends AnyVal {

@inline
def orZero: Double = value.flat getOrElse 0.0
Expand All @@ -62,7 +62,7 @@ object JsUnderOrHelper {
* UndefOr Integer Extensions
* @param value the given [[js.UndefOr value]]
*/
implicit class UndefOrIntExtensions(val value: js.UndefOr[Int]) extends AnyVal {
implicit final class UndefOrIntExtensions(val value: js.UndefOr[Int]) extends AnyVal {

@inline
def orZero: Int = value.flat getOrElse 0
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/io/scalajs/util/OptionHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object OptionHelper {
* Option Extensions
* @param valueA the given [[Option optional value]]
*/
implicit class OptionExtensions[T](val valueA: Option[T]) extends AnyVal {
implicit final class OptionExtensions[T](val valueA: Option[T]) extends AnyVal {

@inline def ?==(valueB: js.UndefOr[T]): Boolean = valueA.exists(v => valueB.exists(_ == v))

Expand All @@ -39,7 +39,7 @@ object OptionHelper {
* Option Boolean Extensions
* @param value the given [[Option value]]
*/
implicit class OptionBoolExtensions(val value: Option[Boolean]) extends AnyVal {
implicit final class OptionBoolExtensions(val value: Option[Boolean]) extends AnyVal {

@inline def isTrue: Boolean = value.contains(true)

Expand All @@ -49,7 +49,7 @@ object OptionHelper {
* Option Double Extensions
* @param value the given [[Option value]]
*/
implicit class OptionDoubleExtensions(val value: Option[Double]) extends AnyVal {
implicit final class OptionDoubleExtensions(val value: Option[Double]) extends AnyVal {

@inline def orZero: Double = value getOrElse 0.0

Expand All @@ -59,7 +59,7 @@ object OptionHelper {
* Option Integer Extensions
* @param value the given [[Option value]]
*/
implicit class OptionIntExtensions(val value: Option[Int]) extends AnyVal {
implicit final class OptionIntExtensions(val value: Option[Int]) extends AnyVal {

@inline def orZero: Int = value getOrElse 0

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/io/scalajs/util/PromiseHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ object PromiseHelper {
* @param task the given [[Future task]]
* @tparam T the return type of the task
*/
implicit class TimeExtensions[T](val task: Future[T]) extends AnyVal {
implicit final class TimeExtensions[T](val task: Future[T]) extends AnyVal {

@inline
def withTimer(action: String, showHeader: Boolean = false)(implicit ec: ExecutionContext): Future[T] = {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/io/scalajs/util/ScalaJsHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object ScalaJsHelper {
* js.Dynamic to Value Extensions
* @param obj the given [[js.Dynamic object]]
*/
implicit class JsAnyExtensions(val obj: js.Any) extends AnyVal {
implicit final class JsAnyExtensions(val obj: js.Any) extends AnyVal {

@inline
def asUndefOr[T]: js.UndefOr[T] = obj.asInstanceOf[js.UndefOr[T]].flat
Expand Down Expand Up @@ -61,7 +61,7 @@ object ScalaJsHelper {
* js.Array Extensions
* @param array the given [[js.Array array]]
*/
implicit class JsArrayExtensions[A](val array: js.Array[A]) extends AnyVal {
implicit final class JsArrayExtensions[A](val array: js.Array[A]) extends AnyVal {

@inline
def indexWhereOpt(f: A => Boolean): Option[Int] = array.indexWhere(f) match {
Expand All @@ -83,7 +83,7 @@ object ScalaJsHelper {
* js.Dictionary Extensions
* @param dict the given [[js.Dictionary dictionary]]
*/
implicit class JsDictionaryExtensions[A](val dict: js.Dictionary[A]) extends AnyVal {
implicit final class JsDictionaryExtensions[A](val dict: js.Dictionary[A]) extends AnyVal {

@inline
def replaceWith(items: (String, A)*): Unit = {
Expand Down