Giter Site home page Giter Site logo

Comments (13)

mxcl avatar mxcl commented on May 22, 2024

Well, now we have files() and directories, so I guess I should make directories a function too.

from path.swift.

ConfusedVorlon avatar ConfusedVorlon commented on May 22, 2024

I guess that's the most minimal consistent implementation.

personally, I have no issue with var directories as a duplicate for func directories()
and var files as an duplicate for func files()

from path.swift.

mxcl avatar mxcl commented on May 22, 2024

I have no issue with var directories as a duplicate for func directories()

Swift doesnโ€™t allow this, though I think it would if directories() had a parameter, so perhaps I can do it for files.

from path.swift.

mxcl avatar mxcl commented on May 22, 2024

Anyway, almost done. Coming up.

from path.swift.

ConfusedVorlon avatar ConfusedVorlon commented on May 22, 2024

thank you :)

from path.swift.

ConfusedVorlon avatar ConfusedVorlon commented on May 22, 2024

as you say, swift does allow duplication if there is a parameter - even if that param has a default value
so, I just put this in a playground

class Foo {
    var bar:[String] {
        return ["this"]
    }
    
    func bar(test:Bool = true) -> [String] {
        return ["that"]
    }
}


let test = Foo()
test.bar
test.bar()

if you want duplicates on directory(), then you'd just need to think of an obscure filter method param and provide a nil default

func directories(startingWith:String? = nil)

from path.swift.

mxcl avatar mxcl commented on May 22, 2024

Refs #22

from path.swift.

mxcl avatar mxcl commented on May 22, 2024

K released: https://github.com/mxcl/Path.swift/releases/tag/0.10.0

CocoaPods will deploy when CI for the tag succeeds.

from path.swift.

mxcl avatar mxcl commented on May 22, 2024

If you found my help useful, please consider reimbursing my time by contributing to my Patreon. Thank you so much!

from path.swift.

ConfusedVorlon avatar ConfusedVorlon commented on May 22, 2024

that's great - thank you.

from path.swift.

ConfusedVorlon avatar ConfusedVorlon commented on May 22, 2024

thinking about this a bit more as I work through my own app; It would actually make complete sense for the directories and files APIs to match up exactly, including filtering for extensions.

Extensions on directories seems odd until you think that file bundles are actually directories with extensions.

So Path("~/Applications").directories(withExtension:"app")

is actually useful

on a related note, filtering should probably handle case sensitivity to be properly useful.
It's pretty common for images to turn up as .JPG as well as .jpg

func files(withExtension ext: String? = nil, caseSensitive:Bool = false)

I'm happy to send these in as pull requests. Let me know if that would help.

from path.swift.

mxcl avatar mxcl commented on May 22, 2024

I'm actually considering dropping the extensions-specialization and having the user do the filtering themselves.

ls().files().filter{ ["jpg", "jpeg"] =~ $0.extension.lowercased() }

from path.swift.

ConfusedVorlon avatar ConfusedVorlon commented on May 22, 2024

yup - seems reasonable. I didn't know about =~ on an array

alternatively, how about a chaining approach with a convenience filter (this has to be a super common use case)

public extension Array where Element == Entry {
 func filter(withExtensions:[String],caseSensitive:Bool = false) -> [Entry]
}

that way files and directories can both be var, and you can chain if you want a filter

ls().files.filter(withExtensions:["jpg","png"])

from path.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.