swift 开发神兵利器,Dollar

官网地址:https://github.com/ankurp/Dollar

 

Dollar 是一个第三方扩展。

包括了。Array,Dictionary,Object,Function,Chaining

导入Dollar 直接使用即可

数组扩展操作


func dollarArrayTest(){
    //取对应数组 组成新的数组
    print(Dollar.at(["ant","bat","cat","dog","egg"], indexes: [0,2,4]))
    //分成多个数组
    print(Dollar.chunk([1,2,3,4],size: 2))
    print(Dollar.chunk([1,2,3,4],size: 3))
    //找出第二个数组中。第一个数组没有的值
    print(Dollar.difference([1,2,3,4,5],[5,2,10]))
    //根据条件和array分组
    print(Dollar.groupBy([1,2,3,4,5], callback: {$0 % 2 }))
    //得到数组出现的次数
    print(Dollar.frequencies(["a","d","c","a","d","v"]))
    //得到数组最大公约数
    print(Dollar.gcd(3,9))
    //计算交集
    print(Dollar.intersection([1,2,3],[5,2,1,4],[2,1]))
    //计算并集
    print(Dollar.union([1,2,3],[1,23,3]))
    //得到数组最小公倍数
    print(Dollar.lcm(3, 9))
    //配对组合新 出租
    print(Dollar.transpose([[1,2,3],[4,5,6]]))
}

输出结果

2020-09-11 22:45:37.001952+0800 安果视频壁纸[6488:367125] [Storyboard] Unknown class Ma in Interface Builder file.
["ant", "cat", "egg"]
[[1, 2], [3, 4]]
[[1, 2, 3], [4]]
[1, 3, 4]
[0: [2, 4], 1: [1, 3, 5]]
["a": 2, "v": 1, "d": 2, "c": 1]
3
[2, 1]
[1, 2, 3, 23]
9
[[1, 4], [2, 5], [3, 6]]

字典扩展操作。

func dollarDictTest(){
    let dict:Dictionary<String,Int> = ["Dog":1,"Cat":2]
    let dict2:Dictionary<String,Int> = ["Cow":3]
    let dict3:Dictionary<String,Int> = ["Sheep":4]
    //合并
    print(Dollar.merge(dict,dict2,dict3))
    // 选择
    print(Dollar.pick(["Dog":1,"Cat":2,"Cow":3], keys: "Dog","Cow"))
    //省略
    print(Dollar.omit(["Dog":1,"Cat":2,"Cow":3], keys: "Cat","Dog"))
}

结果

字典扩展
["Dog": 1, "Cat": 2, "Cow": 3, "Sheep": 4]
["Dog": 1, "Cow": 3]
["Cow": 3]

科里化 curry

func dollarFunctest(){
    let curriedAdder = Dollar.curry(adder)
    let addTenAnd = curriedAdder(10)
    let addThirtyAnd = addTenAnd(20)
    print(addThirtyAnd(1))
     print(addThirtyAnd(50))
         print(addTenAnd(10)(10))
}

 

结果

curry 
31
80
30

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安果移不动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值