List Ops

in ita •  7 months ago 

class ListOps {

static append(list1, list2) {
    list1+list2
}

static concatenate(lists) {
    lists.collectMany{ it }
}

static filter(list, fn) {
    list.findAll fn
}

static length(list) {
    list.size()
}

static map(list, fn) {
    list.collect fn
}

static foldl(list, fn, initial) {
    list.inject(initial, {acc, elm-> fn(acc,elm)})
}

static foldr(list, fn, initial) {
    list.reverse().inject(initial, {acc, elm-> fn(acc,elm)})
}


static reverse(list) {
    list.reverse()
}

}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.