用法:
f ∘ g
編寫函數:即 (f ∘ g)(args...; kwargs...)
表示 f(g(args...; kwargs...))
。 ∘
符號可以通過鍵入 \circ<tab>
在 Julia REPL(以及大多數編輯器,適當配置)中輸入。
函數組合也以前綴形式工作:∘(f, g)
與 f ∘ g
相同。前綴形式支持多個函數的組合:∘(f, g, h) = f ∘ g ∘ h
和 splatting ∘(fs...)
用於組合函數的可迭代集合。
Julia 1.4
多函數組合至少需要 Julia 1.4。
Julia 1.5
一個函數 ∘(f) 的組合至少需要 Julia 1.5。
Julia 1.7
使用關鍵字參數至少需要 Julia 1.7。
例子
julia> map(uppercase∘first, ["apple", "banana", "carrot"])
3-element Vector{Char}:
'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase)
'B': ASCII/Unicode U+0042 (category Lu: Letter, uppercase)
'C': ASCII/Unicode U+0043 (category Lu: Letter, uppercase)
julia> fs = [
x -> 2x
x -> x/2
x -> x-1
x -> x+1
];
julia> ∘(fs...)(3)
3.0
另見
、ComposedFunction
。!f::Function
相關用法
- Julia :<=用法及代碼示例
- Julia :==方法用法及代碼示例
- Julia :\方法用法及代碼示例
- Julia :|用法及代碼示例
- Julia :*方法用法及代碼示例
- Julia :|>用法及代碼示例
- Julia ://用法及代碼示例
- Julia :^方法用法及代碼示例
- Julia :!==用法及代碼示例
- Julia :>>>用法及代碼示例
- Julia :<<用法及代碼示例
- Julia :!=用法及代碼示例
- Julia :>=用法及代碼示例
- Julia :-方法用法及代碼示例
- Julia :⊈用法及代碼示例
- Julia :⊊用法及代碼示例
- Julia :<用法及代碼示例
- Julia :+用法及代碼示例
- Julia :~用法及代碼示例
- Julia :/用法及代碼示例
- Julia :!用法及代碼示例
- Julia :>用法及代碼示例
- Julia :>>用法及代碼示例
- Julia ::用法及代碼示例
- Julia :∉用法及代碼示例
注:本文由純淨天空篩選整理自julialang.org 大神的英文原創作品 Base.:∘ — Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。