Work on mapping variant cases#37
Conversation
|
Okay, I added an extensible version ( Just need better names and docs. 😁 |
|
Thank you for working on this. I haven't reviewed everything in detail, but I have a couple of API thoughts. The type of case_
# over _foo (\a -> show a)
# over _bar (\a -> a + 1)
case_ # overMatch
{ foo: \a -> show a
, bar: \a -> a + 1
}
expand
# over _foo ...
# over _bar ...
expand # overMatch ... |
|
I'm not super concerned about catering to the |
|
I'm revisiting this PR since I'm looking at Here's an example usage that I think is important to keep clean: |
Also remove redundant variable `r4` and the corresponding constraint
src/Data/Variant.purs
Outdated
| traverse | ||
| ∷ ∀ r rl ri ro r1 r2 r3 m | ||
| . RL.RowToList r rl | ||
| ⇒ VariantTravCases m rl ri ro |
There was a problem hiding this comment.
This is a small nit, but I think the library tends to use full names where possible, so I'd consider renaming this to VariantTraverseCases
src/Data/Functor/Variant.purs
Outdated
| coerceR = unsafeCoerce | ||
|
|
||
| -- | Traverse over some labels (with access to the containers) and use | ||
| -- | `travers f` for the rest (just changing the index type). |
There was a problem hiding this comment.
| -- | `travers f` for the rest (just changing the index type). | |
| -- | `traverse f` for the rest (just changing the index type). |
src/Data/Variant.purs
Outdated
| import Data.Symbol (class IsSymbol, reflectSymbol) | ||
| import Data.Variant.Internal (class Contractable, class VariantMatchCases) as Exports | ||
| import Data.Variant.Internal (class Contractable, class VariantMatchCases, class VariantTags, BoundedDict, BoundedEnumDict, VariantCase, VariantRep(..), contractWith, lookup, lookupCardinality, lookupEq, lookupFirst, lookupFromEnum, lookupLast, lookupOrd, lookupPred, lookupSucc, lookupToEnum, unsafeGet, unsafeHas, variantTags) | ||
| import Data.Variant.Internal (class Contractable, class VariantMapCases, class VariantMatchCases) as Exports |
There was a problem hiding this comment.
Should this also re-export VariantTraverseCases?
|
I'm still looking through the constraints here, but I have reason to use |
|
My usage of |
|
I think if y'all are both satisfied with with the implementation/constraints and documentation, then I'm fine with y'all moving forward. I don't currently have any other constructive feedback. |
|
Other than my naming and import comments I've mentioned above, this looks perfectly good to me. |
|
@natefaubion I'm happy with the current state of things. |
|
Release away! |
Fixes #36.
This is a work-in progress. In particular, I don't know of a way to come up with the correct
mapfunction for theVariantFthat is generated frommapSome. Will we have to collectmapdictionaries (corresponding tororow), and then search for it in there?Note:
mapAllhas a different implementation frommapSomeonly because the compiler doesn't solveUnion r () r, and it is a constraint I don't want to propagate to the user. Otherwise it would bemapAll r = mapSome r case_.Also need to write tests. All in good time 😉