I want to do what I think is the simplest thing, map through a plain old Javascript object, using fp-ts constructs.
There are a lot of operators I would like to use — map
, filterMap
, and so on — but they seem to require the Map
type (which I assume is the Javascript Map object) — and there does not seem to be any easy way to convert back and forth between Map and Javascript object, which in Typescript is the standard representation of algebraic data types and of its Record<K,V> type.
This seems like a pretty big hole. Please don’t tell me I have to switch to lodash...
map(f, obj)
to be basically the same asf(obj)
. With this in mind, you could use a functor for the object which would allow you to callmap
on it. Again, I don't know fp-ts but it should have an identity functor under some name.object
. There is amap
for List and for Map, just none for objects.map(v => v+1)({a: 6})
to compile (which it does not do now) and yield{a: 7}
.map(v => v+1)(new Map([['a', 6]]))
does work and does yieldMap([['a', 7]])
but is not what I want. Ps. Why does Javascript have a concept calledmap
and another calledMap
and they are almost totally different? How about “AssociativeArray” or “Dictionary”?.map()
defines an association of an item with another item via a function. You can think of capital M Map is a noun, while lowercase m map is a verb. One is a