-
文脈を持った値に関数を適用する
f a
に(a -> b)
を適用したい
-
r -> a
からr -> b
にfmap :: (Functor f) => (a -> b) -> f a -> f 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
struct User { | |
let username: String | |
} | |
extension User: CustomStringConvertible { | |
var description: String { return "username: \(username)" } | |
} | |
// DAO |
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
#import <UIKit/UIKit.h> | |
@interface MyPickerView : UIView | |
<UIPickerViewDataSource, UIPickerViewDelegate> | |
{ | |
UIToolbar *toolbar; | |
UIPickerView *picker; | |
void (^completion)(NSString *selected); |
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
#import <Foundation/Foundation.h> | |
@interface YSNetwork : NSObject | |
@property (readonly) NSURL *URL; | |
@property (strong, nonatomic) NSURLRequest *request; | |
@property (strong, nonatomic) NSString *userAgent; | |
@property (strong, nonatomic, readonly) NSData *responseData; | |
@property (strong, nonatomic, readonly) NSDictionary *responseHeader; | |
@property (strong, nonatomic) void (^completion)(NSDictionary *responseHeader, NSData *responseData); | |
@property (strong, nonatomic) void (^failure)(NSError *error); |
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
import System.Environment (getArgs) | |
import Data.Char (digitToInt) | |
spare = (==) '/' | |
strike = (==) 'X' | |
updateBonus r (b1, b2) | |
| spare r = (b2 + 1, 0) | |
| strike r = (b2 + 1, 1) | |
| otherwise = (b2, 0) |
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
import System.Environment (getArgs) | |
main = do | |
(x:_) <- getArgs | |
mapM_ putStrLn $ createFizzBuzz $ read x | |
createFizzBuzz :: Int -> [String] | |
createFizzBuzz 0 = [] | |
createFizzBuzz x = map fizzbuzz [1..x] |
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
import System.Environment (getArgs) | |
import Prelude hiding (head, tail) | |
import Data.Char (ord) | |
sudden :: String -> String | |
sudden s = unlines [head s, body s, tail s] | |
body :: String -> String | |
body s = "> 突然の" ++ s ++ " <" |
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
data Akari a = Waai a (Akari a) | Daisuki deriving (Show) | |
data H oo gle = H oo oo oo oo oo gle deriving (Show) | |
data Ha y oo = Ha y oo oo oo oo oo deriving (Show) | |
data O b = OOOO|OOOOOO|O|OO deriving (Show) | |
data Hom r a = Hom (r -> a) | |
data State s a = State (s -> (a, s)) | |
data Just a = Nothing | Maybe (Maybe a) | |
instance Functor Akari where | |
fmap _ Daisuki = Daisuki |
NewerOlder