Functions

The following functions are available globally.

  • Execute an operation in the current task subject to a timeout.

    Throws

    Throws TimedOutError if the timeout expires before operation completes. If operation throws an error before the timeout expires, that error is propagated to the caller.

    Declaration

    Swift

    public func withTimeout<T: Sendable>(
        seconds: TimeInterval,
        body: @escaping @Sendable () async throws -> T
    ) async throws -> T

    Parameters

    seconds

    The duration in seconds operation is allowed to run before timing out.

    operation

    The async operation to perform.

    Return Value

    Returns the result of operation if it completed in time.

  • Undocumented

    Declaration

    Swift

    public func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> (A) -> (B) -> C
  • Undocumented

    Declaration

    Swift

    public func curry<A, B, C>(_ f: @escaping (A, B) throws -> C) -> (A) -> (B) throws -> C
  • Undocumented

    Declaration

    Swift

    public func curry<A, B, C>(_ f: @escaping (A, B) async throws -> C) -> (A) -> (B) async throws -> C
  • Undocumented

    Declaration

    Swift

    public func curryFirst<A, B>(_ f: @escaping (A) -> B) -> (A) -> () -> B
  • Undocumented

    Declaration

    Swift

    public func curryFirst<A, B>(_ f: @escaping (A) async throws -> B) -> (A) -> () async throws -> B
  • Undocumented

    Declaration

    Swift

    public func curryFirst<A, B, C>(_ f: @escaping (A, B) -> C) -> (A) -> (B) -> C
  • Undocumented

    Declaration

    Swift

    public func curryFirst<A, B, C>(_ f: @escaping (A, B) async throws -> C) -> (A) -> (B) async throws -> C
  • Undocumented

    Declaration

    Swift

    public func curryFirst<A, B, C, D>(_ f: @escaping (A, B, C) -> D) -> (A) -> (B, C) -> D
  • Undocumented

    Declaration

    Swift

    public func curryFirst<A, B, C, D>(_ f: @escaping (A, B, C) async throws -> D) -> (A) -> (B, C) async throws -> D

Atoms

  • An atom represents state in Recoil. The atom() function returns a writeable RecoilState object.

    Declaration

    Swift

    public func atom<T: Equatable>(_ value: T,
                                   funcName: String = #function,
                                   fileID: String = #fileID,
                                   line: Int = #line) -> Atom<T>

    Return Value

    A writeable RecoilState object.

  • An atom represents state in Recoil. The atom() function returns a writeable RecoilState object.

    Declaration

    Swift

    public func atom<T: Equatable>(_ fn: @escaping () -> T,
                                   funcName: String = #function,
                                   fileID: String = #fileID,
                                   line: Int = #line) -> Atom<T>

    Return Value

    A writeable RecoilState object.

  • An atom represents state in Recoil. The atom() function returns a writeable RecoilState object.

    Declaration

    Swift

    public func atom<T: Equatable, E: Error>(_ fn: @escaping AtomCombineGet<T, E>,
                                             funcName: String = #function,
                                             fileID: String = #fileID,
                                             line: Int = #line) -> AsyncAtom<T>

    Return Value

    A writeable RecoilState object.

  • An atom represents state in Recoil. The atom() function returns a writeable RecoilState object.

    Declaration

    Swift

    public func atom<T: Equatable>(_ fn: @escaping AtomAsyncGet<T>,
                                   funcName: String = #function,
                                   fileID: String = #fileID,
                                   line: Int = #line) -> AsyncAtom<T>

    Return Value

    A writeable RecoilState object.

Families

  • A atomFamily is a powerful pattern that is similar to a atom, but allows you to pass parameters

    Declaration

    Swift

    public func atomFamily<P: Hashable, T: Equatable>(
        _ getBody: @escaping AtomFamilyGet<P, T>,
        funcName: String = #function,
        fileID: String = #fileID,
        line: Int = #line
    ) -> AtomFamily<P, T>

    Parameters

    getBody

    A function that is passed an object of named callbacks that returns the value of the atom

    Return Value

    A function which can be called with user-defined parameters and returns a selector. Each unique parameter value will return the same memoized selector instance.

  • A atomFamily is a powerful pattern that is similar to a atom, but allows you to pass parameters

    Declaration

    Swift

    public func atomFamily<P: Hashable, T: Equatable, E: Error>(
        _ getBody: @escaping AtomFamilyCombineGet<P, T, E>,
        funcName: String = #function,
        fileID: String = #fileID,
        line: Int = #line
    ) -> AsyncAtomFamily<P, T>

    Parameters

    getBody

    A function that can pass an user-defined parameter.

    Return Value

    A function which can be called with user-defined parameters and returns a asynchronous atom with combine. Each unique parameter value will return the same memoized atom instance.

  • A atomFamily is a powerful pattern that is similar to a atom, but allows you to pass parameters

    Declaration

    Swift

    public func atomFamily<P: Hashable, T: Equatable>(
      _ getBody: @escaping AtomFamilyAsyncGet<P, T>,
      funcName: String = #function,
      fileID: String = #fileID,
      line: Int = #line
    ) -> AsyncAtomFamily<P, T>

    Parameters

    getBody

    A function that can pass an user-defined parameter.

    Return Value

    A function which can be called with user-defined parameters and returns a asynchronous atom with async/await. Each unique parameter value will return the same memoized atom instance.

  • A selectorFamily is a powerful pattern that is similar to a selector, but allows you to pass parameters

    Declaration

    Swift

    public func selectorFamily<P: Hashable, T: Equatable>(
        _ getBody: @escaping SelectorFamilyGet<P, T>,
        funcName: String = #function,
        fileID: String = #fileID,
        line: Int = #line
    ) -> SelectorFamily<P, T>

    Parameters

    getBody

    A function that is passed an object of named callbacks that returns the value of the selector

    Return Value

    A function which can be called with user-defined parameters and returns a selector. Each unique parameter value will return the same memoized selector instance.

  • A selectorFamily is a powerful pattern that is similar to a selector, but allows you to pass parameters

    Declaration

    Swift

    public func selectorFamily<P: Hashable, T: Equatable, E: Error>(
        _ getBody: @escaping SelectorFamilyCombineGet<P, T, E>,
        funcName: String = #function,
        fileID: String = #fileID,
        line: Int = #line
    ) -> AsyncSelectorFamily<P, T>

    Parameters

    getBody

    A function that can pass an user-defined parameter. and it evaluates the value for the derived state.

    Return Value

    A function which can be called with user-defined parameters and returns a asynchronous selector with combine. Each unique parameter value will return the same memoized selector instance.

  • A selectorFamily is a powerful pattern that is similar to a selector, but allows you to pass parameters

    Declaration

    Swift

    public func selectorFamily<P: Hashable, T: Equatable>(
        _ getBody: @escaping SelectorFamilyAsyncGet<P, T>,
        funcName: String = #function,
        fileID: String = #fileID,
        line: Int = #line
    ) -> AsyncSelectorFamily<P, T>

    Parameters

    getBody

    A function that can pass an user-defined parameter. and it evaluates the value for the derived state.

    Return Value

    A function which can be called with user-defined parameters and returns a asynchronous selector with async/await. Each unique parameter value will return the same memoized selector instance.

Sync Selector

  • A Selector represent a derived state in Recoil. If only a get function is provided, the selector is read-only and returns a Readonly Selector

    Declaration

    Swift

    public func selector<T: Equatable>(_ getBody: @escaping SyncGet<T>,
                                       funcName: String = #function,
                                       fileID: String = #fileID,
                                       line: Int = #line) -> Selector<T>

    Return Value

    A synchronous readonly selector.

  • A Selector represent a derived state in Recoil. If only a get function is provided, the selector is read-only and returns a Readonly Selector

    Declaration

    Swift

    public func selector<T: Equatable, E: Error>(_ getBody: @escaping CombineGet<T, E>,
                                                 funcName: String = #function,
                                                 fileID: String = #fileID,
                                                 line: Int = #line) -> AsyncSelector<T>

    Return Value

    A asynchronous readonly selector with combine.

  • A Selector represent a derived state in Recoil. If only a get function is provided, the selector is read-only and returns a Readonly Selector

    Declaration

    Swift

    public func selector<T: Equatable>(_ getBody: @escaping AsyncGet<T>,
                                       funcName: String = #function,
                                       fileID: String = #fileID,
                                       line: Int = #line) -> AsyncSelector<T>

    Return Value

    A asynchronous readonly selector with async/await.

  • A Selector represent a derived state in Recoil. If the get and set function are provided, the selector is writeable

    Declaration

    Swift

    public func selector<T: Equatable>(get getBody: @escaping SyncGet<T>,
                                       set setBody: @escaping SetBody<T>,
                                       funcName: String = #function,
                                       fileID: String = #fileID,
                                       line: Int = #line) -> MutableSelector<T>

    Return Value

    A asynchronous readonly selector with async/await.

  • A hook provide an API for your callbacks to work with Recoil state. Diffrent with other hooks, the hook don’t load state, until you manually call it. Asynchronously read Recoil state without subscribing a component to re-render if the atom or selector is updated.

    Declaration

    Swift

    @MainActor
    public func useRecoilCallback<Return>(_ fn: @escaping Callback<Return>) -> () -> Return

    Parameters

    fn

    A function that you want to access the Recoil state

    Return Value

    return a callback function that can trigger state update after call it

  • Undocumented

    Declaration

    Swift

    @MainActor
    public func useRecoilCallback<Return>(_ fn: @escaping AsyncCallback<Return>) -> () async throws -> Return
  • A hook provide an API for your callbacks to work with Recoil state. Diffrent with other hooks, the hook don’t load state, until you manually call it. Asynchronously read Recoil state without subscribing a component to re-render if the atom or selector is updated.

    Declaration

    Swift

    @MainActor
    public func useRecoilCallback<P, R>(_ fn: @escaping Callback1<P, R>) -> (P) -> R

    Parameters

    fn

    A function that you want to access the Recoil state with one user-defined parameter

    Return Value

    return a callback function that can trigger state update after call it

  • Undocumented

    Declaration

    Swift

    @MainActor
    public func useRecoilCallback<P, R>(_ fn: @escaping AsyncCallback1<P, R>) -> (P) async throws -> R
  • A hook provide an API for your callbacks to work with Recoil state. Diffrent with other hooks, the hook don’t load state, until you manually call it. Asynchronously read Recoil state without subscribing a component to re-render if the atom or selector is updated.

    Declaration

    Swift

    @MainActor
    public func useRecoilCallback<P1, P2, R>(_ fn: @escaping Callback2<P1, P2, R>) -> (P1, P2) -> R

    Parameters

    fn

    A function that you want to access the Recoil state with two user-defined parameters

    Return Value

    return a callback function that can trigger state update after call it

  • Undocumented

    Declaration

    Swift

    @MainActor
    public func useRecoilCallback<P1, P2, R>(_ fn: @escaping AsyncCallback2<P1, P2, R>) -> (P1, P2) async throws -> R
  • A hook will subscribe the component to re-render if there are changing in the Recoil state.

    Declaration

    Swift

    @MainActor
    public func useRecoilValue<P: Equatable, Return: RecoilSyncNode>(
        _ value: RecoilParamNode<P, Return>
    ) -> Return.T?

    Parameters

    value

    Selectors which with user-defined parameters

    Return Value

    return a readable inner value that wrapped in recoil state. if the state is async state, it return will 'value?', otherwise it return 'value'

  • Undocumented

    Declaration

    Swift

    @MainActor
    public func useRecoilValue<P: Equatable, Return: RecoilAsyncNode>(
        _ value: RecoilParamNode<P, Return>
    ) -> Return.T?
  • A hook will subscribe the component to re-render if there are changing in the Recoil state.

    Declaration

    Swift

    @MainActor
    public func useRecoilValue<Value>(_ initialState: Value) -> Value.T? where Value : RecoilSyncNode

    Parameters

    value

    a recoil state (atom or selector)

    Return Value

    return a readable inner value that wrapped in recoil state. if the state is async state, it return will 'value?', otherwise it return 'value'

  • Undocumented

    Declaration

    Swift

    @MainActor
    public func useRecoilValue<Value>(_ initialState: Value) -> Value.T? where Value : RecoilAsyncNode
  • A hook will subscribe the component to re-render if there are changing in the Recoil state.

    Declaration

    Swift

    @MainActor
    public func useRecoilState<P: Equatable, Return: RecoilMutableSyncNode>(
        _ value: RecoilParamNode<P, Return>
    ) -> Binding<Return.T>

    Parameters

    initialState

    a writeable recoil state wrapper which with a recoil state and user-defined parameters

    Return Value

    return a Binding value that wrapped in recoil state. if the state is async state, it return will 'Binding<value?>', otherwise it return 'Binding<value>'

  • A hook will subscribe the component to re-render if there are changing in the Recoil state.

    Declaration

    Swift

    @MainActor
    public func useRecoilState<Value>(_ initialState: Value) -> Binding<Value.T> where Value : RecoilSyncNode, Value : Writeable

    Parameters

    initialState

    a writeable recoil state(atom or writeable selector)

    Return Value

    return a Binding value that wrapped in recoil state. if the state is async state, it return will 'Binding<value?>', otherwise it return 'Binding<value>'

  • A hook is intended to be used for reading the value of asynchronous selectors. eg: You can get the loading, error status with this hooks

    Declaration

    Swift

    @MainActor
    public func useRecoilValueLoadable<P: Equatable, Return: RecoilNode>(
        _ value: RecoilParamNode<P, Return>
    ) -> LoadableContent<Return.T>

    Parameters

    value

    A selector wrapper which with user-defined parameters

    Return Value

    return a loadable object that contains loading informations

  • A hook is intended to be used for reading the value of asynchronous selectors. eg: You can get the loading, error status with this hooks

    Declaration

    Swift

    @MainActor
    public func useRecoilValueLoadable<Value>(_ value: Value) -> LoadableContent<Value.T> where Value : RecoilNode

    Parameters

    value

    A selector

    Return Value

    return a loadable object that contains loading informations