Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Result[A] = Either[ Seq[ Error ], A ] //Type of Error is immaterial
- //If I have a case class Border that takes Width and Color
- case class Border( width: SizeUnit, color: Color )
- //then what I will invoke fn2 below as such:
- //This function composese results.
- //Just like apply of Border would take
- //width and color and return Border
- //this would take a Result(width), Result(color)
- //and return Result(border)
- def composeResultn2[ A, B, R ](
- resa: Result[ A ],
- resb: Result[ B ]
- f: (A,B) => R
- ) : Result[ R ] = {
- ( resa, resb ) match{
- case( Right( a ), Right( b ) ) => Right( f( a, b ) )
- case _ => Left(
- Seq( a.left, b.left )
- .map( _.toOption )
- .flatten.flatten
- )
- }
- //Invocation of composeResult2
- composeResult2(
- Right( SizeUnit( 3 ) ),
- Left( Error( "SomeError" ) ),
- Border.apply
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement