how can add external php function or class to theme file? As I asked above, is it possible to add or include externally written classes or functions files to drupal theme files e.g 'theme_name.theme' file?
A .theme file is processed as PHP - anything you can do in a PHP file, you can do in your theme's .theme file.

So if you want a service:

$some_service = \Drupal::service('foo');


Or a function from a module file:

module_load_include('inc', 'foo_module');


And so on.