11module Static
22
33import IfElse: ifelse
4+ using SciMLPublic: @public
45
56export StaticInt, StaticFloat64, StaticSymbol, True, False, StaticBool, NDIndex
6- export dynamic, is_static, known, static, static_promote
7+ export dynamic, is_static, known, static, static_promote, static_first, static_step,
8+ static_last
9+
10+ @public OptionallyStaticRange,
11+ OptionallyStaticUnitRange, OptionallyStaticStepRange, SUnitRange, SOneTo
12+ @public eachop, eachop_tuple, reduce_tup, eq, ne, gt, ge, le, lt, mul, add
713
814import PrecompileTools: @recompile_invalidations
915
@@ -12,7 +18,7 @@ import PrecompileTools: @recompile_invalidations
1218end
1319
1420"""
15- StaticSymbol
21+ StaticSymbol(S::Symbol)::StaticSymbol{S}
1622
1723A statically typed `Symbol`.
1824"""
@@ -33,7 +39,7 @@ Base.Symbol(@nospecialize(s::StaticSymbol)) = known(s)
3339abstract type StaticInteger{N} <: Number end
3440
3541"""
36- StaticBool(x::Bool) -> True/ False
42+ StaticBool(x::Bool)::Union{ True, False}
3743
3844A statically typed `Bool`.
3945"""
@@ -55,7 +61,7 @@ function StaticBool(x::Bool)
5561end
5662
5763"""
58- StaticInt(N::Int) -> StaticInt{N}()
64+ StaticInt(N::Int):: StaticInt{N}
5965
6066A statically sized `Int`.
6167Use `StaticInt(N)` instead of `Val(N)` when you want it to behave like a number.
@@ -68,7 +74,7 @@ struct StaticInt{N} <: StaticInteger{N}
6874end
6975
7076"""
71- IntType(x::Integer) -> Union{Int,StaticInt}
77+ IntType(x::Integer):: Union{Int, StaticInt}
7278
7379`IntType` is a union of `Int` and `StaticInt`. As a function, it ensures that `x` one of the
7480two.
@@ -256,9 +262,10 @@ function static(x::X) where {X}
256262end
257263
258264"""
259- is_static(::Type{T}) -> StaticBool
265+ is_static(::Type{T})::Union{True, False}
260266
261- Returns `True` if `T` is a static type.
267+ If `T` is a static type return `static(true)::True` and otherwise returns
268+ `static(false)::False`
262269
263270See also: [`static`](@ref), [`known`](@ref)
264271"""
@@ -582,7 +589,7 @@ permute(@nospecialize(x::Tuple), @nospecialize(perm::Val)) = permute(x, static(p
582589end
583590
584591"""
585- eachop(op, args...; iterator::Tuple{Vararg{StaticInt}}) -> Tuple
592+ Static. eachop(op, args...; iterator::Tuple{Vararg{StaticInt}}):: Tuple
586593
587594Produces a tuple of `(op(args..., iterator[1]), op(args..., iterator[2]),...)`.
588595"""
592599eachop (:: F , :: Tuple{} , args:: Vararg{Any} ) where {F} = ()
593600
594601"""
595- eachop_tuple(op, arg, args...; iterator::Tuple{Vararg{StaticInt}}) -> Type{Tuple}
602+ Static. eachop_tuple(op, arg, args...; iterator::Tuple{Vararg{StaticInt}}):: Type{Tuple}
596603
597604Produces a tuple type of `Tuple{op(arg, args..., iterator[1]), op(arg, args..., iterator[2]),...}`.
598605Note that if one of the arguments passed to `op` is a `Tuple` type then it should be the first argument
@@ -781,66 +788,109 @@ end
781788end
782789
783790"""
784- eq(x, y)
791+ Static. eq(x, y)::Union{Bool, True, False}
785792
786- Equivalent to `!= ` but if `x` and `y` are both static returns a `StaticBool.
793+ Equivalent to `== ` but if `x` and `y` are static the return value is a `StaticBool.
787794"""
788795eq (x:: X , y:: Y ) where {X, Y} = ifelse (is_static (X) & is_static (Y), static, identity)(x == y)
796+
797+ """
798+ Static.eq(x)::Base.Fix2{typeof(Static.eq}}
799+
800+ Create a function that compares `x` to other values using `Static.eq` (i.e. a
801+ function equivalent to `y -> Static.eq(y, x)`).
802+ """
789803eq (x) = Base. Fix2 (eq, x)
790804
791805"""
792- ne(x, y)
806+ Static. ne(x, y)::Union{Bool, True, False}
793807
794- Equivalent to `!=` but if `x` and `y` are both static returns a `StaticBool.
808+ Equivalent to `!=` but if `x` and `y` are static the return value is a `StaticBool.
795809"""
796810ne (x:: X , y:: Y ) where {X, Y} = ! eq (x, y)
811+
812+ """
813+ Static.ne(x)::Base.Fix2{typeof(Static.ne}}
814+
815+ Create a function that compares `x` to other values using `Static.ne` (i.e. a
816+ function equivalent to `y -> Static.ne(y, x))`.
817+ """
797818ne (x) = Base. Fix2 (ne, x)
798819
799820"""
800- gt (x, y)
821+ Static.ne (x, y)::Union{Bool, True, False}
801822
802- Equivalent to `>` but if `x` and `y` are both static returns a `StaticBool.
823+ Equivalent to `>` but if `x` and `y` are static the return value is a `StaticBool.
803824"""
804825gt (x:: X , y:: Y ) where {X, Y} = ifelse (is_static (X) & is_static (Y), static, identity)(x > y)
826+
827+ """
828+ Static.gt(x)::Base.Fix2{typeof(Static.gt}}
829+
830+ Create a function that compares `x` to other values using `Static.gt` (i.e. a
831+ function equivalent to `y -> Static.gt(y, x))`.
832+ """
805833gt (x) = Base. Fix2 (gt, x)
806834
807835"""
808- ge(x, y)
836+ Static. ge(x, y)::Union{Bool, True, False}
809837
810- Equivalent to `>=` but if `x` and `y` are both static returns a `StaticBool.
838+ Equivalent to `>=` but if `x` and `y` are static the return value is a `StaticBool.
811839"""
812840ge (x:: X , y:: Y ) where {X, Y} = ifelse (is_static (X) & is_static (Y), static, identity)(x >= y)
841+
842+ """
843+ Static.ge(x)::Base.Fix2{typeof(Static.ge}}
844+
845+ Create a function that compares `x` to other values using `Static.ge` (i.e. a
846+ function equivalent to `y -> Static.ge(y, x)`).
847+ """
813848ge (x) = Base. Fix2 (ge, x)
814849
815850"""
816- le(x, y)
851+ Static. le(x, y)::Union{Bool, True, False}
817852
818- Equivalent to `<=` but if `x` and `y` are both static returns a `StaticBool.
853+ Equivalent to `<=` but if `x` and `y` are static the return value is a `StaticBool.
819854"""
820855le (x:: X , y:: Y ) where {X, Y} = ifelse (is_static (X) & is_static (Y), static, identity)(x <= y)
856+
857+ """
858+ Static.le(x)::Base.Fix2{typeof(Static.le}}
859+
860+ Create a function that compares `x` to other values using `Static.le` (i.e. a
861+ function equivalent to `y -> Static.le(y, x)`).
862+ """
821863le (x) = Base. Fix2 (le, x)
822864
823865"""
824- lt(x, y)
866+ Static. lt(x, y)::Union{Bool, True, False}
825867
826- Equivalent to `<` but if `x` and `y` are both static returns a `StaticBool.
868+ Equivalent to `<` but if `x` and `y` are static the return value is a `StaticBool.`
827869"""
828870lt (x:: X , y:: Y ) where {X, Y} = ifelse (is_static (X) & is_static (Y), static, identity)(x < y)
871+
872+ """
873+ Static.lt(x)::Base.Fix2{typeof(Static.lt}}
874+
875+ Create a function that compares `x` to other values using `Static.lt` (i.e. a
876+ function equivalent to y -> Static.lt(y, x)).
877+ """
829878lt (x) = Base. Fix2 (lt, x)
830879
831880"""
832- mul(x) -> Base.Fix2(*, x)
833- mul(x, y) ->
881+ Static.mul(x)::Base.Fix2{typeof(*)}
834882
835- Equivalent to `*` but allows for lazy multiplication when passing functions.
883+ Create a function that multiplies `x` with other values (i.e. a function
884+ equivalent to `y -> y * x`).
836885"""
837886mul (x) = Base. Fix2 (* , x)
838887
839888"""
840- add(x) -> Base.Fix2(+, x)
841- add(x, y) ->
889+ Static. add(x) -> Base.Fix2(+, x)
890+ Static. add(x, y)
842891
843- Equivalent to `+` but allows for lazy addition when passing functions.
892+ Create a function that adds `x` to other values (i.e. a function equivalent to
893+ `y -> y + x`).
844894"""
845895add (x) = Base. Fix2 (+ , x)
846896
@@ -966,15 +1016,17 @@ end
9661016 return (Base. to_index (A, I[1 ]), to_indices (A, indstail, Base. tail (I))... )
9671017end
9681018
969- function Base. show (io:: IO , @nospecialize (x:: Union{StaticNumber, StaticSymbol, NDIndex} ))
1019+ function Base. show (@nospecialize (io:: IO ), @nospecialize (x:: Union {
1020+ StaticNumber, StaticSymbol, NDIndex}))
9701021 show (io, MIME " text/plain" (), x)
9711022end
972- function Base. show (io:: IO , :: MIME"text/plain" ,
973- @nospecialize (x:: Union{StaticNumber, StaticSymbol} ))
1023+ function Base. show (
1024+ @nospecialize (io:: IO ), :: MIME"text/plain" , @nospecialize (x:: Union {
1025+ StaticNumber, StaticSymbol}))
9741026 print (io, " static(" * repr (known (typeof (x))) * " )" )
9751027 nothing
9761028end
977- function Base. show (io:: IO , m:: MIME"text/plain" , @nospecialize (x:: NDIndex ))
1029+ function Base. show (@nospecialize ( io:: IO ) , m:: MIME"text/plain" , @nospecialize (x:: NDIndex ))
9781030 print (io, " NDIndex" )
9791031 show (io, m, Tuple (x))
9801032 nothing
0 commit comments