<commit_before>[![GitHub tag](https://img.shields.io/github/tag/XCEssentials/FunctionalState.svg)](https://github.com/XCEssentials/FunctionalState/releases)
[![CocoaPods](https://img.shields.io/cocoapods/v/XCEFunctionalState.svg)](https://cocoapods.org/?q=XCEFunctionalState)
[![CocoaPods](https://img.shields.io/cocoapods/p/XCEFunctionalState.svg)](https://cocoapods.org/?q=XCEFunctionalState)
[![license](https://img.shields.io/github/license/XCEssentials/FunctionalState.svg)](https://opensource.org/licenses/MIT)

# Introduction

Turn any object into discrete system and describe its states declaratively.



# How to install

The recommended way is to install using [CocoaPods](https://cocoapods.org/?q=XCEFunctionalState):

```ruby
pod 'XCEFunctionalState', '~> 2.6'
```



# How it works

This library allows to turn any object into [discrete system](https://en.wikipedia.org/wiki/Discrete_system) by defining a number of distinct states and then applying these states instantly or via transition.



# How to use

A typical use case for this library is for re-configuring instances of `UIView` and its subclasses as your app state changes.



## State

Each state of a given object is represented by two closures. Each of these closures gets an instance of the object as input parameter and supposed to make mutations on internal object members. All such mutations together define a distinct state of the object.

First closure - `onSet` -  is required and declares mutations that must be made when the object transitions into the state. Second closure - `onUpdate` - is optional and declares mutations that must be made when the object transitions into the state and when the same state it is being applied again.



## Stateful

Let's say we have a class that represents a view with a text field where user can input their search keyword and a button that will start the search process when it's tapped:

```swift
class SearchView: UIView<commit_msg>Minor fix in Readme<commit_after>[![GitHub tag](https://img.shields.io/github/tag/XCEssentials/FunctionalState.svg)](https://github.com/XCEssentials/FunctionalState/releases)
[![CocoaPods](https://img.shields.io/cocoapods/v/XCEFunctionalState.svg)](https://cocoapods.org/?q=XCEFunctionalState)
[![CocoaPods](https://img.shields.io/cocoapods/p/XCEFunctionalState.svg)](https://cocoapods.org/?q=XCEFunctionalState)
[![license](https://img.shields.io/github/license/XCEssentials/FunctionalState.svg)](https://opensource.org/licenses/MIT)

# Introduction

Turn any object into discrete system and describe its states declaratively.



# How to install

The recommended way is to install using [CocoaPods](https://cocoapods.org/?q=XCEFunctionalState):

```ruby
pod 'XCEFunctionalState', '~> 2.7'
```



# How it works

This library allows to turn any object into [discrete system](https://en.wikipedia.org/wiki/Discrete_system) by defining a number of distinct states and then applying these states instantly or via transition.



# How to use

A typical use case for this library is for re-configuring instances of `UIView` and its subclasses as your app state changes.



## State

Each state of a given object is represented by two closures. Each of these closures gets an instance of the object as input parameter and supposed to make mutations on internal object members. All such mutations together define a distinct state of the object.

First closure - `onSet` -  is required and declares mutations that must be made when the object transitions into the state. Second closure - `onUpdate` - is optional and declares mutations that must be made when the object transitions into the state and when the same state it is being applied again.



## Stateful

Let's say we have a class that represents a view with a text field where user can input their search keyword and a button that will start the search process when it's tapped:

```swift
class SearchView: UIView
{'fraction_non_alphanumeric': 0.0891492613346918, 'fraction_numerical': 0.0010188487009679063, 'mean_word_length': 4.914156626506024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1132083', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1073, 'n_words': 434}