/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ export function Left < T , U > ( val ) { return new Either < T , U > ( val ) ; } export function Right < T , U > ( val ) { return new Either < T , U > ( undefined , val ) ; } export class Either < T , U > { left ? : T ; right ? : U ; constructor ( left ? , right ? ) { this . left = left ; this . right = right ; } map < V > ( f ) { return map ( f , this ) ; } mbind < V > ( f ) { return mbind ( f , this ) ; } } export function match < T , U , V > ( left , right , either ) { if ( either . left != undefined ) { return left ( either . left ! ) ; } else { return right ( either . right ! ) ; } } export function map < T , U , V > ( f , either ) { const left = function ( t ) { return Left < T , V > ( either . left ! ) ; } ; const right = function ( u ) { return Right < T , V > ( f ( either . right ! ) ) ; } ; return match ( left , right , either ) ; } export function mbind < T , U , V > ( f , either ) { const left = function ( t ) { return Left < T , V > ( either . left ! ) ; } ; const right = function ( u ) { return f ( either . right ! ) ; } ; return match ( left , right , either ) ; } export function munit < T , U > ( u ) { return Right < T , U > ( u ) ; } export function and < T , A , B > ( a , b ) { return mbind ( ( rightA ) => mbind ( ( rightB ) => Right < T , [ A , B ] > ( [ rightA , rightB ] ) , b ) , a ) ; }