有一种函子具有功能(monad <a>, function A -&gt; monad<b>) -&gt; Monad<b>

时间:2018-07-05 04:40:31

标签: functional-programming

There's a pattern in my code (Java) which looks like:

private M<State2> augmentFromDS3(M<State1> state1) {
    return state1.flatMap(this::transform1);
}


private M<State3> validatePersonType1(M<State2> state2) {
    return state2.flatMap(this::transform2);
}

private M<State2> 
transform1(State1 state1) {
}

private M<State3> 
transform2(State2 state2) {
}

There's also a version which calls map.

This feels like there's a functional pattern (like a monad transformer, comonad, etc.) here that has been found before. However, I don't know what the name is for the kind of thing I think is there.

1 个答案:

答案 0 :(得分:3)

通过查看问题的标题,我认为这是Haskell(或Scala中的flatMap)中monad的bind(>> =)函数:

(>>=)  :: m a -> (a -> m b) -> m b