relude-random icon indicating copy to clipboard operation
relude-random copied to clipboard

Add traverse and sequence

Open mlms13 opened this issue 6 years ago • 2 comments

Just want to make a note so I don't forget...

let traverse: ('a => Generator.t('b), list('a)) => Generator.t(list('b));
let sequence: list(Generator.t('a)) => Generator.t(list('a));

Naming is a bit of an issue, since this is primarily a list traversal, so Generator.traverse is pretty misleading. Generator.List.traverse feels backward for the same reason (especially when you consider the existence of List.Option.traverse in the ecosystem). Generator.ListOf makes the backward-ness more clear, but seems cumbersome. Maybe just Generator.listTraverse?

mlms13 avatar Jan 08 '20 23:01 mlms13

Just to add a data point, for things that are specialized to list/etc., I've been naming things with whateverAsList and whateverAsArray, so these could be traverseAsList and sequenceAsList - that way, you can find them via auto-suggest, but it's clear they are specialized.

andywhite37 avatar Jan 08 '20 23:01 andywhite37

Good call on the auto-suggest. I'll follow the same pattern.

mlms13 avatar Jan 09 '20 00:01 mlms13