gpt4 book ai didi

cyclops.data.Zipper类的使用及代码示例

转载 作者:知者 更新时间:2024-03-20 17:06:31 25 4
gpt4 key购买 nike

本文整理了Java中cyclops.data.Zipper类的一些代码示例,展示了Zipper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Zipper类的具体详情如下:
包路径:cyclops.data.Zipper
类名称:Zipper

Zipper介绍

暂无

代码示例

代码示例来源:origin: aol/cyclops

public Option<Zipper<T>> position(int index) {
  Zipper<T> result = this;
  while (index != result.index()) {
    if (result.index() < index && !result.isEnd()) {
      result = result.next(result);
    } else if (result.index() > index && !result.isStart()) {
      result = result.previous(result);
    } else {
      return Option.none();
    }
  }
  return Option.some(result);
}
public <R> Option<Zipper<T>> next(){

代码示例来源:origin: aol/cyclops

public Zipper<T> filterLeft(Predicate<? super T> predicate) {
  return of(left.filter(predicate),point,right);
}

代码示例来源:origin: aol/cyclops

public  Zipper<Tuple2<T,T>> zip(Zipper<T> zipper){
  return zip(zipper, Tuple::tuple);
}

代码示例来源:origin: aol/cyclops

@Test
public void index() throws Exception {
  assertThat(z.index(),equalTo(3));
  assertThat(z.next().orElse(z2).index(),equalTo(4));
  assertThat(z.previous().orElse(z2).index(),equalTo(2));
}

代码示例来源:origin: aol/cyclops

public Zipper<T> cycleNext() {
  return left.fold(cons->right.fold(c->next().orElse(this), nil->{
    return of(LazySeq.empty(),cons.head(),cons.tail().append(point));
  }),nil->this);
}
public Zipper<T> cyclePrevious() {

代码示例来源:origin: aol/cyclops

public Zipper<T> cyclePrevious() {
  return right.fold(cons->left.fold(c->previous().orElse(this), nil->{
    ImmutableList.Some<T> reversed = cons.reverse();
    return of(reversed.tail().reverse().prepend(point),reversed.head(), LazySeq.empty());
  }),nil->this);
}
public <R> Option<Zipper<T>> previous(){

代码示例来源:origin: aol/cyclops

@Test
public void cyclePrevious() throws Exception {
  System.out.println(z.previous().orElse(z2));
  assertThat(z.cyclePrevious(),equalTo(z.previous().orElse(z2)));
  assertThat(Zipper.of(LazySeq.empty(),5,LazySeq.of(1,2,3)).cyclePrevious(),equalTo(Zipper.of(LazySeq.of(5,1,2),3,LazySeq.empty())));
}

代码示例来源:origin: aol/cyclops

@Test
public void cycleNext() throws Exception {
  assertThat(z.cycleNext(),equalTo(z.next().orElse(z2)));
  assertThat(Zipper.of(LazySeq.of(1,2,3),5,LazySeq.empty()).cycleNext(),equalTo(Zipper.of(LazySeq.empty(),1,LazySeq.of(2,3,5))));
}

代码示例来源:origin: aol/cyclops

@Test
public void zip1() throws Exception {
  assertThat(z.zip(z2),equalTo(Zipper.of(LazySeq.of(tuple(1,40),tuple(2,20),tuple(3,60)),
                    tuple(5,50),
                      LazySeq.of(tuple(10,1),tuple(20,2),tuple(30,3)))));
}

代码示例来源:origin: aol/cyclops

public static <T> Zipper<T> of(ImmutableList<T> left, T value, ImmutableList<T> right){
  return new Zipper<>(left,value,right);
}
public static <T> Zipper of(ReactiveSeq<T> left, T value, ReactiveSeq<T> right){

代码示例来源:origin: aol/cyclops

public <R> Zipper<T> next(Zipper<T> alt){
  return next().orElse(alt);
}
public <R> Zipper<T> previous(Zipper<T> alt){

代码示例来源:origin: aol/cyclops

public <R> Zipper<T> previous(Zipper<T> alt){
  return previous().orElse(alt);
}
public Zipper<T> cycleNext() {

代码示例来源:origin: aol/cyclops

@Test
public void getPoint() throws Exception {
  assertThat(z.getPoint(),equalTo(5));
  assertThat(z.next().orElse(z2).getPoint(),equalTo(10));
}

代码示例来源:origin: aol/cyclops

@Test
public void isStart() throws Exception {
  assertFalse(z.isStart());
  assertTrue(z.position(0).orElse(z2).isStart());
}

代码示例来源:origin: aol/cyclops

@Test
public void isEnd() throws Exception {
  assertFalse(z.isEnd());
  assertTrue(z.position(6).orElse(z2).isEnd());
}

代码示例来源:origin: aol/cyclops

@Test
public void start() throws Exception {
  System.out.println(z.start());
  System.out.println(Zipper.of(LazySeq.empty(),1,LazySeq.of(2,3,5,10,20,30)));
  assertThat(z.start(),equalTo(Zipper.of(LazySeq.empty(),1,LazySeq.of(2,3,5,10,20,30))));
}

代码示例来源:origin: aol/cyclops

@Test
public void getRight() throws Exception {
  assertThat(z.getRight(),equalTo(right));
  assertThat(z.next().orElse(z2).getRight(),equalTo(LazySeq.of(20,30)));
}

代码示例来源:origin: aol/cyclops

@Test
public void left() throws Exception {
  assertThat(z.left(10),equalTo(Zipper.of(LazySeq.of(1,2,3),10,LazySeq.of(5,10,20,30))));
}

代码示例来源:origin: aol/cyclops

@Test
public void map() throws Exception {
  assertThat(z.map(i->((int)0)-i),equalTo(Zipper.of(LazySeq.of(-1,-2,-3),-5,LazySeq.of(-10,-20,-30))));
}

代码示例来源:origin: aol/cyclops

@Test
public void deleteLeftAndRight() throws Exception {
  assertThat(z.deleteAllLeftAndRight(),equalTo(Zipper.of(LazySeq.empty(),5,LazySeq.empty())));
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com