flyingmutant / rapid

Rapid is a modern Go property-based testing library
https://pkg.go.dev/pgregory.net/rapid
Mozilla Public License 2.0
588 stars 25 forks source link

Add Map function for Generator #45

Closed elliot-u410 closed 1 year ago

elliot-u410 commented 1 year ago

Love this library! Thank you!

Right now if I want to map a function over a generator, I must use rapid.Custom. Would a simpler Map function be possible where it lets me simply define the translation between two types?

flyingmutant commented 1 year ago

Thanks for the kind words!

To map a function over a generator, you should use Transform. Before generics it was a method of the Generator called Map, but since methods can't be generic in Go, it became a top-level function (and was renamed to Transform to not be confused with the MapOf series of generators).

Maybe it is a good idea to rename Transform to Map, hmm.

elliot-u410 commented 1 year ago

Ah, I'm not sure how I missed that. As long as it exists, the name isn't as important to me. Thank you.

flyingmutant commented 1 year ago

(I'll leave this open for some time so that I don't forget about possible renaming).