records = $records; } public function run( Collection $data ) { $translations = Obj::prop( 'batch', $data ) ? $this->fetchBatchStrings( Obj::prop( 'strings', $data ) ) : $this->fetchSingleString( $data ); if ( $translations !== false ) { return Either::of( $translations ); } else { return Either::left( 'invalid data' ); } } private function fetchBatchStrings( $strings ) { $results = Fns::map( [ $this, 'fetchSingleString' ], $strings ); return Lst::includes( false, $results ) ? false : $results; } public function fetchSingleString( $data ) { $string = Obj::prop( 'string', $data ); $source = Obj::prop( 'source', $data ); $target = Obj::prop( 'target', $data ); if ( $string && $source && $target ) { return $this->records->get( [ $string ], $source, $target ); } else { return false; } } }