when<R> method

R? when<R>(
  1. {R file(
    1. File file
    )?,
  2. R directory(
    1. Directory directory
    )?,
  3. R link(
    1. Link link
    )?}
)

Handle every possible FS entity.

Implementation

R? when<R>({
  R Function(File file)? file,
  R Function(Directory directory)? directory,
  R Function(Link link)? link,
}) {
  if (fs.isFileSync(path)) {
    return file?.call(this as File);
  } else if (fs.isDirectorySync(path)) {
    return directory?.call(this as Directory);
  } else {
    return link?.call(this as Link);
  }
}