`toString` is not idempotent for strings?
See original GitHub issueSomewhat surprisingly:
R.toString('abc'); //=> "\"abc\""
'abc'.toString(); //=> "abc"
Is it intended?
http://ramdajs.com/repl/?v=0.23.0#?toString('abc')%3B %2F%2F%3D> '"abc"'
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (17 by maintainers)
Top Results From Across the Web
What is the JSLint approved way to convert a number to a ...
I believe that the JSLint approved way is to call .toString() on the number: var stringified = 1..toString(); // Note the use of...
Read more >String.prototype.toString() - JavaScript - MDN Web Docs
The toString() method returns a string representing the specified string value.
Read more >Function.prototype.toString revision - TC39
If the object was defined using ECMAScript code and the returned string representation is not in the form of a MethodDefinition or GeneratorMethod...
Read more >Query idempotence - DataStax Java Driver
The driver does not parse query strings, so it can't infer it automatically (except for statements coming from the query builder, see below)....
Read more >What are Idempotent and Safe methods of HTTP and REST ...
Safe methods are HTTP methods that do not modify the resource like a GET request is safe ... (answer); 3 ways to convert...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree with @dmitriz that the name
R.toString()
is surprising and I would expect it to be idempotent for Strings.For a beginner the similarities between JavaScript’s functional torso in Array’s
map
,filter
,reduce
, etc. and Ramda’sR.map
,R.filter
,R.reduce
are obvious. Then there are functions likeR.test
andR.match
which just dispatch to JS. Fine. However, except for Numbers,R.toString
has nothing to do with JavaScript’stoString()
.I still have not encountered a situation there
R.toString()
could come in handy:JSON.stringify()
,String.quote()
(orJSON.stringify()
),Number.toString(10)
(orJSON.stringify()
),Idempotence: The JS
toString()
method is often used to ensure that a variable is of type String if one is in doubt whether it is a Number or already a String. ApplyingR.toString()
a number of times results in multiply quoted strings.Oh I see, I’ve thought that kind of method is also called
inspect
.toString
reads like the JS traditional type conversion to String, which is also identical with Lodash:https://lodash.com/docs/4.17.4#toString
I understand that Ramda is different from Lodash, but still find it unfortunate that methods with the same name produce different results.