目录
目录README.md

Main Nightly

𝑓(x) FunctionalAPI

Some collection of functions and types that are useful in day to day development.


Functions

map

To help a bit with composability some existing map functions defined on Array and Result are made as global symbols.


public func map<A,B>(_ a: [A], _ f: (A) -> B) -> [B] { ... 

public func map<A,B>(_ a: Result<A,Error> , _ f: (A) -> B) -> Result<B, Error> { ...

Map on Optionals

Please chceck OptionalAPI Swift Package for maps and other extensions on Optional.

identity

Whole implementation looks like this:

func identity<A>(_ a: A) -> A { a }

This might seem as a useless function but every time you write in your code { $0 } you are writing this exact same function. Let’s see some example:

[1,2,3].map{ $0 } // [1,2,3]

Same cane be done with identity but with extra clarity:

[1,2,3].map( identity ) // [1,2,3]

Where this function is useful?

It depends what you need. I use it to generate variations in my snapshot tests. One array contains device, other size class, language direction… you get the idea ;)

🐇🕳 Rabbit Hole

This project is part of the 🐇🕳 Rabbit Hole Packages Collection

关于
87.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号