Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

NotBlankString members as extensions #48

Closed
6 tasks
LVMVRQUXL opened this issue Nov 16, 2022 · 0 comments
Closed
6 tasks

NotBlankString members as extensions #48

LVMVRQUXL opened this issue Nov 16, 2022 · 0 comments
Labels
common Should work on all platforms. enhancement New feature or request. types Related to Kotools Types library. wontfix This will not be worked on.

Comments

@LVMVRQUXL
Copy link
Contributor

Description

The problem

Extending the NotBlankString type with an operator like plus is impossible because this operator is shadowed by its function member plus(Any?).

The solution

Declare the operators of the NotBlankString type as extension functions for allowing to extend it with new operators.

Code example

import kotools.types.NotBlankString

val csvExtension = FileExtension.Csv

sealed class FileExtension(private val value: NotBlankString) {
    fun toNotBlankString(): NotBlankString = toString()
    	.toNotBlankString()

    override fun toString(): String = ".$value"
    
    object Csv : FileExtension("csv".toNotBlankString())
}

// This function is shadowed by the NotBlankString.plus(Any?) function.
/** Returns this string suffixed by the [extension]. */
operator fun NotBlankString.plus(extension: FileExtension): NotBlankString = TODO()

fun main(): Unit = println(NotBlankString("file") + csvExtension) // file.csv

Checklist

  • Convert query operations members to extensions.
  • Convert positional access operations to extensions.
  • Convert binary operations to extensions.
  • Test.
  • Refactor.
  • Update Work in progress section in changelog.
@LVMVRQUXL LVMVRQUXL added enhancement New feature or request. common Should work on all platforms. types Related to Kotools Types library. labels Nov 16, 2022
@LVMVRQUXL LVMVRQUXL added this to the Types v4.0.0 milestone Nov 16, 2022
@LVMVRQUXL LVMVRQUXL modified the milestones: Types v4.0.0, Types v3.2.0 Nov 23, 2022
@LVMVRQUXL LVMVRQUXL added the wontfix This will not be worked on. label Dec 8, 2022
@LVMVRQUXL LVMVRQUXL removed this from the Types v4.0.0 milestone Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
common Should work on all platforms. enhancement New feature or request. types Related to Kotools Types library. wontfix This will not be worked on.
Projects
None yet
Development

No branches or pull requests

1 participant