clipperhouse / gen

Type-driven code generation for Go
http://clipperhouse.com/gen/overview/
Other
1.43k stars 90 forks source link

channels #7

Open icholy opened 10 years ago

icholy commented 10 years ago

It would be cool if it could generate similar methods that work on channels.

Something like: http://play.golang.org/p/wr1nZgxi1m

clipperhouse commented 10 years ago

I like it...

rickb777 commented 10 years ago

Nice idea (although the Map function should possibly transform from ThingA to ThingB).

Peter Welch (inventor of the parallel sort algorithm, amongst other things) often talks about channels and goroutines (a.k.a. 'processes') in terms of Lego-like building bricks (more: http://www.cs.kent.ac.uk/projects/ofa/jcsp/). If Gen were to generate code for channel-based generic processes, some of Welch's ideas should be considered.

However, defining a useful set of operations is a rather open-ended task, I fear.

Logiraptor commented 10 years ago

I've written a demo typewriter for pipelines here. It's only about an hour's work so there are definitely rough spots. The biggest challenge with this is early termination. I've had to wrap the channel in a struct instead of just adding methods to it in order to allow an early close feature, but I think it leads to a simple enough api.