This file contains 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
add1 xs n c | |
| c < 0 = reverse $ add1 (reverse xs) n (abs c) | |
| c > 0 = add1' xs n c | |
| c == 0 = add1' xs n (length xs) | |
where | |
add1' [] _ _ = [] | |
add1' xs n 0 = xs | |
add1' (x:xs) n c | |
| x == n = x+1:(add1' xs n (c-1)) | |
| otherwise = x:add1' xs n c |
This file contains 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
The output for the code below is as following, on my Mac. So, the first time that I ask to read the Tags it won't return localized filename or the UTI. But it will on a next invocation of the same code. Duh! | |
2013-10-24 00:10:26.780 Untitled 3[39076:507] Attributes WITHOUT Tags: { | |
NSURLContentAccessDateKey = "2013-10-23 12:38:49 +0000"; | |
NSURLContentModificationDateKey = "2013-10-23 10:33:50 +0000"; | |
NSURLLocalizedNameKey = Applications; | |
NSURLTypeIdentifierKey = "public.folder"; | |
} | |
2013-10-24 00:10:26.781 Untitled 3[39076:507] Attributes WITH Tags: { |
This file contains 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
operator infix ||| {associativity left precedence 100} | |
func ||| <T>(lhs:T?, rhs: @auto_closure () -> T) -> T { | |
if let alhs = lhs { | |
return alhs | |
} else { | |
return rhs() | |
} | |
} |
This file contains 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 noNils(optionals:[Any?]) -> Bool { | |
for item in optionals { | |
if item == nil { | |
return false | |
} | |
} | |
return true | |
} | |
func allSome<A,B>(a:A?, b:B?) -> (A,B)? { |
This file contains 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 catOptionals<T,S where S:SequenceType, S.Generator.Element == Optional<T>>(optionals: S) -> [T] { | |
return reduce(optionals, []) { (acc, value: T?) -> [T] in | |
switch value { | |
case let .Some(v): return acc + [v] | |
default: return acc | |
} | |
} | |
} | |