I have been doing functional programming for quite some time now, but I am new to monoids and other pure abstractions. I am wondering if there is a way to generate a list of values by using concat
function defined for a monoid?
For example, with 0 as identity (unit) and +
as concat
, integers become a monoid. If I want to have a sequence of ordered integers, I could just apply +
to the first integer I need and 1
(which would be a step here), then repeat the process for the result and so on. This would generate a list like [1, 2, 3, 4, 5, ...]
.
Similarly for more complex monoids, if there is Event monoid defined, with special value as identity and concat
such that it takes two Events and produces a new one keeping the same interval, I could have a sequence of [ Event(Today, 12:00), Event(Today, 12:10), Event(Today, 12:20) ]
(so the interval is 10 minutes).
My question is: is there any standard pattern/abstraction/way of genereting such sequences by applying concat
to previous item and a step/interval? I am using fp-ts
library and I tried to find something that could do it, but without any luck. I could use unfold
to generate an array of values, but this function passes only one value to the callback while I need two values for concat
to work