Sort nil to the end of an array of optional strings
If I have an array of optional strings, and I want to sort it in ascending order with nils at the beginning, I can do it easily in a single line:
["b", nil, "a"].sorted{ $0 ?? "" < $1 ?? "" } // [nil, "a", "b"]
But there doesn't seem to be any similarly easy solution to sort nils to the end of the array. It can be easily done with most other simple data types, for instance:
[2, nil, 1].sorted{ $0 ?? Int.max < $1 ?? Int.max } // [1, 2, nil]
For doubles you can do the same with greatestFiniteMagnitude
, for dates you can use distantFuture
. Is there any kind of equivalent for strings, or any other concise way of doing this so I can avoid writing a bunch of messy conditionals?
arrays swift sorting optional
add a comment |
If I have an array of optional strings, and I want to sort it in ascending order with nils at the beginning, I can do it easily in a single line:
["b", nil, "a"].sorted{ $0 ?? "" < $1 ?? "" } // [nil, "a", "b"]
But there doesn't seem to be any similarly easy solution to sort nils to the end of the array. It can be easily done with most other simple data types, for instance:
[2, nil, 1].sorted{ $0 ?? Int.max < $1 ?? Int.max } // [1, 2, nil]
For doubles you can do the same with greatestFiniteMagnitude
, for dates you can use distantFuture
. Is there any kind of equivalent for strings, or any other concise way of doing this so I can avoid writing a bunch of messy conditionals?
arrays swift sorting optional
use"u{ffff}"
instead""
– holex
Nov 22 '18 at 14:05
@holex: What if the string is "😀" aka"u{1f600}"
? How does that compare to"u{ffff}"
? It might work by chance, but I would not recommend using “magic values.”
– Martin R
Nov 25 '18 at 14:18
@MartinR, the idea was showing a potential high-end unicode value here, not an exact value – but agreed there are more elegant solutions (like yours for instance) but most of the devs can't comprehend that.
– holex
Nov 26 '18 at 8:20
add a comment |
If I have an array of optional strings, and I want to sort it in ascending order with nils at the beginning, I can do it easily in a single line:
["b", nil, "a"].sorted{ $0 ?? "" < $1 ?? "" } // [nil, "a", "b"]
But there doesn't seem to be any similarly easy solution to sort nils to the end of the array. It can be easily done with most other simple data types, for instance:
[2, nil, 1].sorted{ $0 ?? Int.max < $1 ?? Int.max } // [1, 2, nil]
For doubles you can do the same with greatestFiniteMagnitude
, for dates you can use distantFuture
. Is there any kind of equivalent for strings, or any other concise way of doing this so I can avoid writing a bunch of messy conditionals?
arrays swift sorting optional
If I have an array of optional strings, and I want to sort it in ascending order with nils at the beginning, I can do it easily in a single line:
["b", nil, "a"].sorted{ $0 ?? "" < $1 ?? "" } // [nil, "a", "b"]
But there doesn't seem to be any similarly easy solution to sort nils to the end of the array. It can be easily done with most other simple data types, for instance:
[2, nil, 1].sorted{ $0 ?? Int.max < $1 ?? Int.max } // [1, 2, nil]
For doubles you can do the same with greatestFiniteMagnitude
, for dates you can use distantFuture
. Is there any kind of equivalent for strings, or any other concise way of doing this so I can avoid writing a bunch of messy conditionals?
arrays swift sorting optional
arrays swift sorting optional
asked Nov 22 '18 at 1:02
John MontgomeryJohn Montgomery
2,77662438
2,77662438
use"u{ffff}"
instead""
– holex
Nov 22 '18 at 14:05
@holex: What if the string is "😀" aka"u{1f600}"
? How does that compare to"u{ffff}"
? It might work by chance, but I would not recommend using “magic values.”
– Martin R
Nov 25 '18 at 14:18
@MartinR, the idea was showing a potential high-end unicode value here, not an exact value – but agreed there are more elegant solutions (like yours for instance) but most of the devs can't comprehend that.
– holex
Nov 26 '18 at 8:20
add a comment |
use"u{ffff}"
instead""
– holex
Nov 22 '18 at 14:05
@holex: What if the string is "😀" aka"u{1f600}"
? How does that compare to"u{ffff}"
? It might work by chance, but I would not recommend using “magic values.”
– Martin R
Nov 25 '18 at 14:18
@MartinR, the idea was showing a potential high-end unicode value here, not an exact value – but agreed there are more elegant solutions (like yours for instance) but most of the devs can't comprehend that.
– holex
Nov 26 '18 at 8:20
use
"u{ffff}"
instead ""
– holex
Nov 22 '18 at 14:05
use
"u{ffff}"
instead ""
– holex
Nov 22 '18 at 14:05
@holex: What if the string is "😀" aka
"u{1f600}"
? How does that compare to "u{ffff}"
? It might work by chance, but I would not recommend using “magic values.”– Martin R
Nov 25 '18 at 14:18
@holex: What if the string is "😀" aka
"u{1f600}"
? How does that compare to "u{ffff}"
? It might work by chance, but I would not recommend using “magic values.”– Martin R
Nov 25 '18 at 14:18
@MartinR, the idea was showing a potential high-end unicode value here, not an exact value – but agreed there are more elegant solutions (like yours for instance) but most of the devs can't comprehend that.
– holex
Nov 26 '18 at 8:20
@MartinR, the idea was showing a potential high-end unicode value here, not an exact value – but agreed there are more elegant solutions (like yours for instance) but most of the devs can't comprehend that.
– holex
Nov 26 '18 at 8:20
add a comment |
3 Answers
3
active
oldest
votes
You can provide a custom comparator which considers nil
as larger than any non-nil value:
let array = ["b", nil, "a", nil]
let sortedArray = array.sorted { (lhs, rhs) -> Bool in
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(sortedArray) // [Optional("a"), Optional("b"), nil, nil]
This works with any array of optional comparable elements, and avoids
the usage of “magical large” values. The comparator can be implemented
as a generic function:
func compareOptionalsWithLargeNil<T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(["b", nil, "a", nil].sorted(by: compareOptionalsWithLargeNil))
// [Optional("a"), Optional("b"), nil, nil]
print([2, nil, 1].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1), Optional(2), nil]
print([3.0, nil, 1.0].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1.0), Optional(3.0), nil]
print([Date(), nil, .distantPast, nil, .distantFuture].sorted(by: compareOptionalsWithLargeNil))
// [Optional(0000-12-30 00:00:00 +0000), Optional(2018-11-22 13:56:03 +0000),
// Optional(4001-01-01 00:00:00 +0000), nil, nil]
Why choose this nameWithLargeNil
?
– ielyamani
Nov 23 '18 at 13:26
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
add a comment |
One nil
is indistinguishable from another. So if you have a working solution that happens to sort as you desire except that nil
entries wind up at the start, use it and then remove the nil
entries and append the same number of nil
entries to the end.
Example:
var arr : [String?] = [nil, "b", nil, "a", nil]
arr = arr.sorted{ $0 ?? "" < $1 ?? "" }
if let ix = arr.firstIndex(where: {$0 != nil}) {
arr = arr.suffix(from: ix) + Array(repeating: nil, count: ix)
}
// [Optional("a"), Optional("b"), nil, nil, nil]
arr
is already avar
, soarr.sort { ... }
instead ofarr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
add a comment |
Your example with Int
gives a clue. If we had a max string value, we could plug that in.
This works for strings that contain only alphabetic characters:
let maxString = "~"
["b", nil, "a"].sorted{ $0 ?? maxString < $1 ?? maxString }
Or simply:
["b", nil, "a"].sorted{ $0 ?? "~" < $1 ?? "~" }
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422533%2fsort-nil-to-the-end-of-an-array-of-optional-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can provide a custom comparator which considers nil
as larger than any non-nil value:
let array = ["b", nil, "a", nil]
let sortedArray = array.sorted { (lhs, rhs) -> Bool in
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(sortedArray) // [Optional("a"), Optional("b"), nil, nil]
This works with any array of optional comparable elements, and avoids
the usage of “magical large” values. The comparator can be implemented
as a generic function:
func compareOptionalsWithLargeNil<T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(["b", nil, "a", nil].sorted(by: compareOptionalsWithLargeNil))
// [Optional("a"), Optional("b"), nil, nil]
print([2, nil, 1].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1), Optional(2), nil]
print([3.0, nil, 1.0].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1.0), Optional(3.0), nil]
print([Date(), nil, .distantPast, nil, .distantFuture].sorted(by: compareOptionalsWithLargeNil))
// [Optional(0000-12-30 00:00:00 +0000), Optional(2018-11-22 13:56:03 +0000),
// Optional(4001-01-01 00:00:00 +0000), nil, nil]
Why choose this nameWithLargeNil
?
– ielyamani
Nov 23 '18 at 13:26
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
add a comment |
You can provide a custom comparator which considers nil
as larger than any non-nil value:
let array = ["b", nil, "a", nil]
let sortedArray = array.sorted { (lhs, rhs) -> Bool in
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(sortedArray) // [Optional("a"), Optional("b"), nil, nil]
This works with any array of optional comparable elements, and avoids
the usage of “magical large” values. The comparator can be implemented
as a generic function:
func compareOptionalsWithLargeNil<T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(["b", nil, "a", nil].sorted(by: compareOptionalsWithLargeNil))
// [Optional("a"), Optional("b"), nil, nil]
print([2, nil, 1].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1), Optional(2), nil]
print([3.0, nil, 1.0].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1.0), Optional(3.0), nil]
print([Date(), nil, .distantPast, nil, .distantFuture].sorted(by: compareOptionalsWithLargeNil))
// [Optional(0000-12-30 00:00:00 +0000), Optional(2018-11-22 13:56:03 +0000),
// Optional(4001-01-01 00:00:00 +0000), nil, nil]
Why choose this nameWithLargeNil
?
– ielyamani
Nov 23 '18 at 13:26
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
add a comment |
You can provide a custom comparator which considers nil
as larger than any non-nil value:
let array = ["b", nil, "a", nil]
let sortedArray = array.sorted { (lhs, rhs) -> Bool in
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(sortedArray) // [Optional("a"), Optional("b"), nil, nil]
This works with any array of optional comparable elements, and avoids
the usage of “magical large” values. The comparator can be implemented
as a generic function:
func compareOptionalsWithLargeNil<T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(["b", nil, "a", nil].sorted(by: compareOptionalsWithLargeNil))
// [Optional("a"), Optional("b"), nil, nil]
print([2, nil, 1].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1), Optional(2), nil]
print([3.0, nil, 1.0].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1.0), Optional(3.0), nil]
print([Date(), nil, .distantPast, nil, .distantFuture].sorted(by: compareOptionalsWithLargeNil))
// [Optional(0000-12-30 00:00:00 +0000), Optional(2018-11-22 13:56:03 +0000),
// Optional(4001-01-01 00:00:00 +0000), nil, nil]
You can provide a custom comparator which considers nil
as larger than any non-nil value:
let array = ["b", nil, "a", nil]
let sortedArray = array.sorted { (lhs, rhs) -> Bool in
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(sortedArray) // [Optional("a"), Optional("b"), nil, nil]
This works with any array of optional comparable elements, and avoids
the usage of “magical large” values. The comparator can be implemented
as a generic function:
func compareOptionalsWithLargeNil<T: Comparable>(lhs: T?, rhs: T?) -> Bool {
switch (lhs, rhs) {
case let(l?, r?): return l < r // Both lhs and rhs are not nil
case (nil, _): return false // Lhs is nil
case (_?, nil): return true // Lhs is not nil, rhs is nil
}
}
print(["b", nil, "a", nil].sorted(by: compareOptionalsWithLargeNil))
// [Optional("a"), Optional("b"), nil, nil]
print([2, nil, 1].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1), Optional(2), nil]
print([3.0, nil, 1.0].sorted(by: compareOptionalsWithLargeNil))
// [Optional(1.0), Optional(3.0), nil]
print([Date(), nil, .distantPast, nil, .distantFuture].sorted(by: compareOptionalsWithLargeNil))
// [Optional(0000-12-30 00:00:00 +0000), Optional(2018-11-22 13:56:03 +0000),
// Optional(4001-01-01 00:00:00 +0000), nil, nil]
edited Nov 22 '18 at 13:58
answered Nov 22 '18 at 9:07
Martin RMartin R
402k56889989
402k56889989
Why choose this nameWithLargeNil
?
– ielyamani
Nov 23 '18 at 13:26
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
add a comment |
Why choose this nameWithLargeNil
?
– ielyamani
Nov 23 '18 at 13:26
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
Why choose this name
WithLargeNil
?– ielyamani
Nov 23 '18 at 13:26
Why choose this name
WithLargeNil
?– ielyamani
Nov 23 '18 at 13:26
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
@Carpsen90: Because it considers nil as larger than any other value, and I could not think of a better name :)
– Martin R
Nov 23 '18 at 13:27
add a comment |
One nil
is indistinguishable from another. So if you have a working solution that happens to sort as you desire except that nil
entries wind up at the start, use it and then remove the nil
entries and append the same number of nil
entries to the end.
Example:
var arr : [String?] = [nil, "b", nil, "a", nil]
arr = arr.sorted{ $0 ?? "" < $1 ?? "" }
if let ix = arr.firstIndex(where: {$0 != nil}) {
arr = arr.suffix(from: ix) + Array(repeating: nil, count: ix)
}
// [Optional("a"), Optional("b"), nil, nil, nil]
arr
is already avar
, soarr.sort { ... }
instead ofarr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
add a comment |
One nil
is indistinguishable from another. So if you have a working solution that happens to sort as you desire except that nil
entries wind up at the start, use it and then remove the nil
entries and append the same number of nil
entries to the end.
Example:
var arr : [String?] = [nil, "b", nil, "a", nil]
arr = arr.sorted{ $0 ?? "" < $1 ?? "" }
if let ix = arr.firstIndex(where: {$0 != nil}) {
arr = arr.suffix(from: ix) + Array(repeating: nil, count: ix)
}
// [Optional("a"), Optional("b"), nil, nil, nil]
arr
is already avar
, soarr.sort { ... }
instead ofarr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
add a comment |
One nil
is indistinguishable from another. So if you have a working solution that happens to sort as you desire except that nil
entries wind up at the start, use it and then remove the nil
entries and append the same number of nil
entries to the end.
Example:
var arr : [String?] = [nil, "b", nil, "a", nil]
arr = arr.sorted{ $0 ?? "" < $1 ?? "" }
if let ix = arr.firstIndex(where: {$0 != nil}) {
arr = arr.suffix(from: ix) + Array(repeating: nil, count: ix)
}
// [Optional("a"), Optional("b"), nil, nil, nil]
One nil
is indistinguishable from another. So if you have a working solution that happens to sort as you desire except that nil
entries wind up at the start, use it and then remove the nil
entries and append the same number of nil
entries to the end.
Example:
var arr : [String?] = [nil, "b", nil, "a", nil]
arr = arr.sorted{ $0 ?? "" < $1 ?? "" }
if let ix = arr.firstIndex(where: {$0 != nil}) {
arr = arr.suffix(from: ix) + Array(repeating: nil, count: ix)
}
// [Optional("a"), Optional("b"), nil, nil, nil]
edited Nov 22 '18 at 2:21
answered Nov 22 '18 at 2:08
mattmatt
331k46541739
331k46541739
arr
is already avar
, soarr.sort { ... }
instead ofarr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
add a comment |
arr
is already avar
, soarr.sort { ... }
instead ofarr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
arr
is already a var
, so arr.sort { ... }
instead of arr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
arr
is already a var
, so arr.sort { ... }
instead of arr = arr.sorted{ ... }
– ielyamani
Nov 23 '18 at 13:48
add a comment |
Your example with Int
gives a clue. If we had a max string value, we could plug that in.
This works for strings that contain only alphabetic characters:
let maxString = "~"
["b", nil, "a"].sorted{ $0 ?? maxString < $1 ?? maxString }
Or simply:
["b", nil, "a"].sorted{ $0 ?? "~" < $1 ?? "~" }
add a comment |
Your example with Int
gives a clue. If we had a max string value, we could plug that in.
This works for strings that contain only alphabetic characters:
let maxString = "~"
["b", nil, "a"].sorted{ $0 ?? maxString < $1 ?? maxString }
Or simply:
["b", nil, "a"].sorted{ $0 ?? "~" < $1 ?? "~" }
add a comment |
Your example with Int
gives a clue. If we had a max string value, we could plug that in.
This works for strings that contain only alphabetic characters:
let maxString = "~"
["b", nil, "a"].sorted{ $0 ?? maxString < $1 ?? maxString }
Or simply:
["b", nil, "a"].sorted{ $0 ?? "~" < $1 ?? "~" }
Your example with Int
gives a clue. If we had a max string value, we could plug that in.
This works for strings that contain only alphabetic characters:
let maxString = "~"
["b", nil, "a"].sorted{ $0 ?? maxString < $1 ?? maxString }
Or simply:
["b", nil, "a"].sorted{ $0 ?? "~" < $1 ?? "~" }
answered Nov 22 '18 at 2:34
Mike TaverneMike Taverne
6,14122141
6,14122141
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422533%2fsort-nil-to-the-end-of-an-array-of-optional-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
use
"u{ffff}"
instead""
– holex
Nov 22 '18 at 14:05
@holex: What if the string is "😀" aka
"u{1f600}"
? How does that compare to"u{ffff}"
? It might work by chance, but I would not recommend using “magic values.”– Martin R
Nov 25 '18 at 14:18
@MartinR, the idea was showing a potential high-end unicode value here, not an exact value – but agreed there are more elegant solutions (like yours for instance) but most of the devs can't comprehend that.
– holex
Nov 26 '18 at 8:20