Giter VIP home page Giter VIP logo

testracunarysequence's Introduction

RACUnarySequence作为RACSequence的子类,Unary的意思是一元的,注释Private class representing a sequence of exactly one value也说明了该类只包含一个值。

完整测试用例在这里

看看.m中方法的作用


+ (instancetype)return:(id)value {
	RACUnarySequence *sequence = [[self alloc] init];
	sequence.head = value;
	return [sequence setNameWithFormat:@"+return: %@", [value rac_description]];
}

重写父类的方法,返回只有一个值的序列。

测试用例:

- (void)test_return
{
    RACUnarySequence *sequence = [RACUnarySequence return:@"xxx"];
    NSLog(@"return -- %@", sequence);
    
    // 打印日志:
    /*
     2018-08-16 17:21:03.940582+0800 TestRACUnarySequence[15973:17015192] return -- <RACUnarySequence: 0x600000238820>{ name = , head = xxx }
     */
}

- (RACSequence *)tail {
	return nil;
}

返回nil。也就是说该类只有一个值。

测试用例:

- (void)test_tail
{
    RACUnarySequence *sequence = [RACUnarySequence return:@[@1, @2, @3]];
    NSLog(@"tail -- %@", sequence.tail);
    
    // 打印日志:
    /*
     2018-08-16 17:22:49.841689+0800 TestRACUnarySequence[16078:17019928] tail -- (null)
     */
}

- (instancetype)bind:(RACStreamBindBlock (^)(void))block {
	RACStreamBindBlock bindBlock = block();
	BOOL stop = NO;

	RACSequence *result = (id)[bindBlock(self.head, &stop) setNameWithFormat:@"[%@] -bind:", self.name];
	return result ?: self.class.empty;
}

head值为参数调用block获取一个RACSequence对象result。如果result存在,返回;如果不存在,返回空序列。

测试用例:

- (void)test_bind
{
    RACUnarySequence *sequence = [RACUnarySequence return:@(1)];
    RACSequence *s = [sequence bind:^RACStreamBindBlock{
        return ^(id value, BOOL *stop) {
            return [RACUnarySequence return:@(100)];
        };
    }];
    NSLog(@"bind -- %@", s);
    
    // 打印日志:
    /*
     2018-08-16 17:25:01.532451+0800 TestRACUnarySequence[16176:17026442] bind -- <RACUnarySequence: 0x6000002341c0>{ name = , head = 100 }
     */
}

后面的一些关于 序列化、格式化日志 的方法不再分析。

综上,这个类只保存一个序列值。

testracunarysequence's People

Contributors

jianghui1 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.