编程

函数式编程概念

  • 函数式编程是一种编程范式
  • 函数式编程 Functional Programming.简写FP
  • 使用特点,将局部小的逻辑计算封装为一个个小的函数体,在实际应用中将这些小的函数体自由组合
  • 可以接受函数当做输入(参数)和输出(返回值)
  • 函数式编程的基础是block闭包
  • 函数式子编程的代表作品:Masnory

代码示例:

make.centerY.equalTo(self.view).offset(100);

做一个函数式Demo

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff; min-height: 13.0px}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #c2349b}span.s3 {font-variant-ligatures: no-common-ligatures; color: #93c86a}span.s4 {font-variant-ligatures: no-common-ligatures; color: #00afca}

-(void)run;
-(void)eat;

-(Person *)run1;
-(Person *)eat1;

-(Person *(^)(CGFloat))run2;
-(Person *(^)(NSString *))eat2;


p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #e44448}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #c2349b}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #c2349b}span.s3 {font-variant-ligatures: no-common-ligatures; color: #00afca}span.s4 {font-variant-ligatures: no-common-ligatures; color: #e44448}span.s5 {font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #e44448}span.s6 {font-variant-ligatures: no-common-ligatures; color: #93c86a}span.s7 {font-variant-ligatures: no-common-ligatures; color: #ffffff}span.s8 {font: 11.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}

-(void)run{
    
    NSLog(@"刘亚华跑");
}
-(void)eat{
    
    NSLog(@"刘亚华吃");
}

-(Person *)run1{
    
    NSLog(@"刘亚华跑不动了");
    return self;
}
-(Person *)eat1{
    
    NSLog(@"刘亚华吃多了");
    return self;
}

-(Person *(^)(NSString *))eat2{
    
    return ^(NSString *xiang){
    
        NSLog(@"刘亚华吃%@吃成saozhu了",xiang);
        
        return self;
    };
}

-(Person *(^)(CGFloat))run2{
    
    return ^(CGFloat dis){
        
        NSLog(@"刘亚华saozhu%f都跑不动了",dis);
        
        return self;
    };
    
}

你可能感兴趣的:(编程)