unisonweb / base_v1

Unison base libraries, published using V1 codebase format
24 stars 14 forks source link

Add swap for Either and Tuple and Weighted implementations #1

Open puffnfresh opened 5 years ago

puffnfresh commented 5 years ago

How do we collaborate on this stuff? Should I even be submitting a pull request?

Either.swap : Either a b -> Either b a
Either.swap e = case e of
  Either.Left a -> Right a
  Either.Right b -> Left b

Weighted.eithers : Weighted a -> Weighted b -> Weighted (Either a b)
Weighted.eithers as bs = Weighted.map Left as <|> Weighted.map Right bs

Tuple.swap : Tuple a b -> Tuple b a
Tuple.swap t = case t of (Tuple.Cons a b) -> Cons b a

Weighted.tuples : Weighted a -> Weighted b -> Weighted (Tuple a b)
Weighted.tuples = Weighted.mergeWith (a b -> Cons a b)
aryairani commented 5 years ago

Thanks @puffnfresh. I'm trying to sort that out right now, and will use yours as a test case :)

francisdb commented 4 years ago

these docs are available right now https://github.com/unisonweb/base/blob/master/CONTRIBUTING.md https://www.unisonweb.org/docs/codebase-organization