docstr: Writes a Serializable object into a file. If the filename is None,
  then this function just returns a string.
  
  Parameters
  ----------
  filename : str or pathlib.Path or None
      Path to the .yaml file.
  Returns
  -------
  out : str
      Serialized object
docstr_tok: ["Writes","a","Serializable","object","into","a","file",".","If","the","filename","is","None",",","then","this","function","just","returns","a","string",".","Parameters","--","--","--","--","--","filename",":","str","or","pathlib.Path","or","None","Path","to","the",".yaml","file",".","Returns","--","--","--","-","out",":","str","Serialized","object"]
code: def to_yaml(self, filename=None):
      """Writes a Serializable object into a file. If the filename is None,
      then this function just returns a string.
  
      Parameters
      ----------
      filename : str or pathlib.Path or None
          Path to the .yaml file.
      Returns
      -------
      out : str
          Serialized object
      """
      res = yaml.safe_dump({"stream": self.to_dict()})
      if filename is not None:
          with open(filename, "w") as f:
              f.write(res)
  
      return res
  
file_path: solt/solt/utils/_utils.py
imports: from functools import wraps
  import json
  import yaml
  import inspect
label_desc: Use image node_id 3 for calling the Serializable obj's underlying member method code with example usage: obj.to_yaml(filename) and returns: res