Skip to content

Add missing docstring for String #7571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion runtime/Stdlib_String.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type t = string

@val external make: 'a => string = "String"
@new external make: 'a => string = "String"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should do that, see:

Bildschirmfoto 2025-06-21 um 14 20 01

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that sounds right, but how does setSymbol work then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, it won't. Seems will only work on string object instances.

So the binding is incorrect IMHO. We'd need another abstract type for string object instances, and could then define getSymbol/setSymbol on that.

I assume this is a pretty niche use case anyway. Personally I never tried setting a value with a symbol key on a string before. Maybe we should just remove the getSymbol/setSymbol bindings from the stdlib?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just remove the getSymbol/setSymbol bindings from the stdlib?
Yes, I think that makes more sense.


@val external fromCharCode: int => string = "String.fromCharCode"
@variadic @val external fromCharCodeMany: array<int> => string = "String.fromCharCode"
Expand Down
66 changes: 64 additions & 2 deletions runtime/Stdlib_String.resi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ String.make(3.5) == "3.5"
String.make([1, 2, 3]) == "1,2,3"
```
*/
@val
@new
external make: 'a => string = "String"

/**
Expand Down Expand Up @@ -121,8 +121,30 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
@variadic @val
external fromCodePointMany: array<int> => string = "String.fromCodePoint"

/**
`equal(str1, str2)` checks if two strings are equal.

## Examples

```rescript
String.equal("hello", "hello") == true
String.equal("hello", "world") == false
String.equal("", "") == true
```
*/
external equal: (string, string) => bool = "%equal"

/**
`compare(str1, str2)` compares two strings, returns an `Ordering.t` value.

## Examples

```rescript
String.compare("hello", "hello") == Ordering.equal
String.compare("apple", "banana") == Ordering.less
String.compare("zebra", "apple") == Ordering.greater
```
*/
external compare: (string, string) => Stdlib_Ordering.t = "%compare"

/**
Expand Down Expand Up @@ -1090,9 +1112,49 @@ String.padEnd("abc", 1, "") == "abc"
@send
external padEnd: (string, int, string) => string = "padEnd"

// TODO: add docs
/**
`getSymbol(str, symbol)` returns the value associated with the given symbol on the string as an `option<'a>`.
Returns `None` if the symbol property doesn't exist.

## Examples

```rescript
let mySymbol = Symbol.make("test")
let h = String.make("hello")
String.setSymbol(h, mySymbol, 42)
String.getSymbol(h, mySymbol) == Some(42)
```
*/
@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = ""

/**
`getSymbolUnsafe(str, symbol)` returns the value associated with the given symbol on the string.

This is _unsafe_, meaning it will return `undefined` if the symbol property doesn't exist.

## Examples

```rescript
let mySymbol = Symbol.make("test")
let h = String.make("hello")
String.setSymbol(h, mySymbol, 43)
String.getSymbolUnsafe(h, mySymbol) == 43
```
*/
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""

/**
`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.

## Examples

```rescript
let mySymbol = Symbol.make("test")
let h = String.make("hello")
String.setSymbol(h, mySymbol, 42)
String.getSymbol(h, mySymbol) == Some(42)
```
*/
@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = ""

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ Path s
"kind": 12,
"tags": [],
"detail": "(string, Symbol.t, 'a) => unit",
"documentation": null,
"documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = String.make(\"hello\")\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"},
"sortText": "setSymbol",
"insertText": "->String.setSymbol",
"additionalTextEdits": [{
Expand Down
Loading