acowley / roshask

Haskell client library for the ROS robotics framework.
BSD 3-Clause "New" or "Revised" License
107 stars 18 forks source link

Add firstThenSecond to Ros.Topic.Util #28

Closed rgleichman closed 9 years ago

rgleichman commented 9 years ago

I created an equivalent function a while ago when I needed to wait for a signal that the PR2 arm had reached its destination before sending the next arm position goal (see waitFor). I think this is a general and basic enough function that it is worth including in Topic.Util.

The test might rely upon implementation details of Topic timing.

I believe bothNew can be written in terms of firstThenSecond as:

bothNew' :: Topic IO a -> Topic IO b -> Topic IO (a, b)
bothNew' x y = Topic $ do
  (x1, x2) <- tee x
  (y1, y2) <- tee y
  runTopic $ merge (firstThenSecond x1 y1) (swap <$> firstThenSecond y2 x2)