(if-let [found (first (filter #(true? ("good" %))))]
(.do_something found)
if found = myarray.detect {|x| x['good'] == true }
found.do_something
end
(if-let [found (first (filter #(true? ("good" %))))]
(.do_something found)
if found = myarray.detect {|x| x['good'] == true }
found.do_something
end
@interface NSObject (Debounce) | |
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay; | |
@end |
#! /bin/sh | |
# usage: <shellscript> [--osx] typename | |
if [ "$1" = "--osx" ] ; then | |
echo ":print_module $2" | xcrun swift -deprecated-integrated-repl | |
else | |
sdk_path=$(echo `xcrun --show-sdk-path` | sed 's#MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk#iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk#') | |
echo ":print_module $1" | xcrun swift -deprecated-integrated-repl -sdk "$sdk_path" | |
fi |
Copy and paste the swift code below into a playground to experiment.
This is a very close emulation of Functor and Monad typeclasses in swift. As of Swift 1.2 and Xcode 6.3, this is no longer very fragile.
Unfortunately, the compiler cannot verify the types when passing a function to (>>=)
. We have to wrap the function in a closure and call it with an explicit argument to compile.
optionalDoubles >>= squareRoot // doesn't compile
optionalDoubles >>= { squareRoot($0) } // compiles