Skip to content

Commit

Permalink
remove unsafe perform inside IO
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangel-dev committed Nov 29, 2019
1 parent a25ceeb commit b7b560e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion project/Component/NefSwiftPlayground/Models/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ extension Module: CustomStringConvertible {
}

extension Module {
static let sourcesLens = Module.lens(for: \.sources)
static let moduleNameAndSourcesTraversal = [Module].traversal + Module.lens(for: \.name).merge(Module.lens(for: \.sources))
static let modulePathAndSourcesTraversal = [Module].traversal + Module.lens(for: \.path).merge(Module.lens(for: \.sources))
}
5 changes: 3 additions & 2 deletions project/Component/NefSwiftPlayground/PlaygroundBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public struct PlaygroundBook {
private func addModules(_ modules: [Module], toPath modulesPath: String) -> EnvIO<FileSystem, PlaygroundBookError, Void> {

func copy(module: Module, to modulesPath: String) -> EnvIO<FileSystem, PlaygroundBookError, Void> {
let dest = IOPartial<PlaygroundBookError>.var(String.self)
return EnvIO { system in
EnvIO { system in
let dest = IOPartial<PlaygroundBookError>.var(String.self)

return binding(
dest <- createModuleDirectory(atPath: modulesPath, andName: module.name).provide(system),
|<-system.copy(itemPaths: module.sources, to: dest.get).mapLeft { _ in .sources(module: module.name) },
Expand Down
21 changes: 13 additions & 8 deletions project/Component/NefSwiftPlayground/SwiftPlayground.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,19 @@ public struct SwiftPlayground {

func linkPathForSources(in modules: [Module]) -> EnvIO<PlaygroundShell, PlaygroundShellError, [Module]> {
EnvIO { shell in
let modules = Module.modulePathAndSourcesTraversal.modify(modules) { (parentPath, sources) in
let linkedSources: [String] = sources.map { source in
shell.linkPath(itemPath: source, parentPath: parentPath).unsafeRunSyncEither().getOrElse("\(parentPath)/\(source)")
}
modules.traverse { (module: Module) in
let sourcesIO = module.sources.map { ($0, module.path) }.traverse(shell.linkPath)^
let moduleIO = sourcesIO.map { sources in
Module.sourcesLens.modify(module, { _ in sources})
}^

return (parentPath, linkedSources)
return moduleIO
}

return IO.pure(modules)^
}
}

return EnvIO { shell in
repos.flatTraverse { repositoryPath in
repos.parFlatTraverse { repositoryPath in
shell.describe(repositoryPath: repositoryPath)
.map(modules)^
.flatMap { modules in linkPathForSources(in: modules).provide(shell) }^
Expand All @@ -169,3 +168,9 @@ public struct SwiftPlayground {
}
}
}

extension Array {
func parFlatTraverse<G: Concurrent, B>(_ f: @escaping (Element) -> Kind<G, [B]>) -> Kind<G, [B]> {
self.k().parFlatTraverse { a in f(a).map { aa in aa.k() } }.map { x in x^.asArray }
}
}
4 changes: 2 additions & 2 deletions project/nef.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2481,8 +2481,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/bow-swift/bow.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.6.0;
branch = master;
kind = branch;
};
};
8B46C433238FDA3300437659 /* XCRemoteSwiftPackageReference "SwiftLine" */ = {
Expand Down

0 comments on commit b7b560e

Please sign in to comment.