given that map
is:
map :: (a -> b) -> [a] -> [b]
why R.map(R.toUpper, 'hello')
returns ['H', 'E', 'L', 'L', 'O']
and not "HELLO"
?
in haskell, for instance, a string is a list of chars, so map toUpper "hello"
behaves as expected (HELLO
).
Shouldn't Ramda's map
be doing the same?
It might be a design choice but I think Ramda's map might be violating the functor law: If we map the id function over a functor, we don't get back the original functor
console.log(
R.map(R.identity, 'Hello World'),
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js" integrity="sha256-xB25ljGZ7K2VXnq087unEnoVhvTosWWtqXB4tAtZmHU=" crossorigin="anonymous"></script>
Why wouldn't I be expecting map
to behave more like:
const map = (fn, string) => string.replace(/./g, fn);
console.log(
map(R.toUpper, 'hello world'),
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js" integrity="sha256-xB25ljGZ7K2VXnq087unEnoVhvTosWWtqXB4tAtZmHU=" crossorigin="anonymous"></script>