This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| // Represents a calculation that could either succeed, or fail with an error message. | |
| enum Result<A> { | |
| // If the calculation was successful, store the result. | |
| case Ok(A) | |
| // If the calculation failed, store the error message. | |
| case Err(String) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T: Collection, U: Collection>(_ base: T, withNewElems: U) -> [T.Iterator.Element] | |
| where T.Iterator.Element == U.Iterator.Element, | |
| T.Iterator.Element: Equatable { | |
| let newElems = withNewElems.filter { !base.contains($0) } | |
| return Array(base) + newElems | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T: Collection, U: Collection>(_ base: T, withNewElems: U) -> [T.Iterator.Element] | |
| where T.Iterator.Element == U.Iterator.Element { | |
| let newElems = withNewElems.filter { !base.contains($0) } | |
| return Array(base) + newElems | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T: Collection, U: Collection>(_ base: T, withNewElems: U) | |
| where T.Iterator.Element == U.Iterator.Element { | |
| // function body will go here | |
| // also ignoring return type for now | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T: Collection, U: Collection>(_ base: T, withNewElems: U) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T: Collection>(_ base: T, withNewElems: T) -> T { | |
| // Ignore the function body for now, | |
| // we’re just trying to make it compile. | |
| return base | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T>(_: Collection, withNewElems: Collection) -> [T] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func extend<T>(_: [T], withNewElems: [T]) -> [T] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let array = Array(0..<10) | |
| let slice = array[2..<5] | |
| // Mixing Array/ArraySlice compiles! | |
| print(extend(array, withNewElems: array)) | |
| print(extend(array, withNewElems: slice)) | |
| print(extend(slice, withNewElems: slice)) | |
| // Mixing Ints/Bools doesn't compile! | |
| print(extend(array, withNewElems: [true, false])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::ffi::OsStr; | |
| use std::io; | |
| use std::fs::{self}; | |
| use std::path::{Path, PathBuf}; | |
| // Find all files in the given directory with the given extension | |
| fn paths_matching(extension: &str, dir: &Path) -> io::Result<Vec<PathBuf>> { | |
| let mut paths: Vec<PathBuf> = Vec::new(); | |
| for entry in fs::read_dir(dir)? { | |
| let entry = entry?; |