Hi Haskell-Cafe,<div><br></div><div>Consider a data type such as</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">data Binding = Binding Var (Either Value [Value])</font></div>
<div><br></div><div>representing a variable bound either to a fixed value or that has a list of possible values.</div><div><br></div><div>I'd like to perform an operation on say, the fixed-value members of a list of bindings. <font class="Apple-style-span" face="'courier new', monospace">Data.Either</font> has "<font class="Apple-style-span" face="'courier new', monospace">partitionEithers</font>"---I'd essentially like to use partitionEithers, but in a way that it "peeks" into the value field of the binding. For the sake of argument, let's say I can't or can't modify <font class="Apple-style-span" face="'courier new', monospace">Binding</font> to move the <font class="Apple-style-span" face="'courier new', monospace">Either</font> to the outside.</div>
<div><br></div><div>What would be an idiomatic Haskell way to accomplish this? Currently I've got "<font class="Apple-style-span" face="'courier new', monospace">liftedPartitionEithers :: [a] -> (a -> Either b c) -> ([a], [a])"</font> which is my own version of <font class="Apple-style-span" face="'courier new', monospace">partitionEithers</font> that calls a selector first. Another option would be to map each Binding to a new datatype that has the Either on the outside, use partitionEithers, and map back.</div>
<div><br></div><div>Thanks,<br>Aran</div><div><br></div><div><br></div><div><br></div>