natefaubion/purescript-routing-duplex

optional/default are not wokring with segment

Closed this issue · 3 comments

Hi,

It seems segment never fails and return empty string in case of failure.
optional and default break because of this.

Can you post a try.purescript.org reproduction? I believe you have misdiagnosed your issue. segment is Parser.take, which does not operate the way you are describing.

take :: RouteParser String
take = Chomp \state ->
case Array.uncons state.segments of
Just { head, tail } -> Success (state { segments = tail }) head
_ -> Fail EndOfPath

That is expected. Internally we do not normalize paths, as this is no longer bidirectional from the source input. If you have a leading /, then that's what the root combinator is for. You can choose to implement normalization yourself (you may not care about strict bidirectionality) by constructing your own pass on top of parsePath.

https://github.com/natefaubion/purescript-routing-duplex/blob/master/src/Routing/Duplex/Parser.purs#L164