DEV Community

Jesse Phillips
Jesse Phillips

Posted on • Edited on

3 1

Iteration with the Previous Result

I am working with zip archives and wanted to create an archive for my unittesting. This creation does no touch the file system so I need to specify the structure.

To facilitate directory structure I'll need to archive the directory tree. Actually for my purposes it looks like I don't but that isn't the point.

I put together this range which allow for create each stage of directory, With Previous.

    import std.path;
    import std.algorithm;
    static assert(r"foo/bar/foobar".pathSplitter
         .withPrevious!buildPath
         .equal([
                buildPath("foo"),
                buildPath("foo","bar"),
                buildPath("foo","bar","foobar")]));

Enter fullscreen mode Exit fullscreen mode

I specify a path as a string and use pathSplitter to provide each part of the path.

I feed this to my withPrevious range and utilizes buildPath to create a OS specific path from components.

The result is equal to each part built on the previous. I don't think I will utilize this for my unittests, but I do like what this provides and is not specific to paths or strings.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post