Rewrite Map in terms of Bind and Return
This commit is contained in:
parent
14d2418d2c
commit
adc85b5572
@ -190,16 +190,7 @@ func Try[In, Out any](p Parser[In, Out]) Parser[In, Out] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Map[In, Out1, Out2 any](p Parser[In, Out1], f func(Out1) Out2) Parser[In, Out2] {
|
func Map[In, Out1, Out2 any](p Parser[In, Out1], f func(Out1) Out2) Parser[In, Out2] {
|
||||||
return func(input State[In]) (bool, Result[In, Out2], error) {
|
return Bind(p, func(out Out1) Parser[In, Out2] {
|
||||||
consumed, reply, err := p(input)
|
return Return[In](f(out))
|
||||||
if err != nil {
|
})
|
||||||
return consumed, Result[In, Out2]{}, err
|
|
||||||
}
|
|
||||||
reply2 := Result[In, Out2]{
|
|
||||||
Value: f(reply.Value),
|
|
||||||
State: reply.State,
|
|
||||||
Message: reply.Message,
|
|
||||||
}
|
|
||||||
return consumed, reply2, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user