alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix

# Scala example source code file (MonadState.scala)

This example Scala source code file (MonadState.scala) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

## The MonadState.scala Scala example source code

```package scalaz

////
/** The class of monads supporting the operations of
* [[scalaz.State]].
*
*/
////
////

def state[A](a: A): F[A] = bind(init)(s => point(a))
def constantState[A](a: A, s: => S): F[A] = bind(put(s))(_ => point(a))
def init: F[S]
def get: F[S]
def gets[A](f: S => A): F[A] = bind(init)(s => point(f(s)))
def put(s: S): F[Unit]
def modify(f: S => S): F[Unit] = bind(init)(s => put(f(s)))

////

}

////

////
}
```

## Other Scala examples (source code examples)

Here is a short list of links related to this Scala MonadState.scala source code file:

 ... this post is sponsored by my books ... #1 New Release! FP Best Seller
{"ft_lang_label":"__label__en","ft_lang_prob":0.5993107,"math_prob":0.9535844,"size":1095,"snap":"2022-27-2022-33","text_gpt3_token_len":303,"char_repetition_ratio":0.13932173,"word_repetition_ratio":0.0116959065,"special_character_ratio":0.34063926,"punctuation_ratio":0.16517857,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9865586,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-28T11:42:30Z\",\"WARC-Record-ID\":\"<urn:uuid:76b31e0e-7f95-4435-992b-7a06a4d8bb27>\",\"Content-Length\":\"8208\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2fa79258-08d0-420f-b1aa-0359aa24f16f>\",\"WARC-Concurrent-To\":\"<urn:uuid:ba8d23b9-85ae-4a24-b7d5-76d288dc3da9>\",\"WARC-IP-Address\":\"45.79.219.226\",\"WARC-Target-URI\":\"https://alvinalexander.com/java/jwarehouse/scalaz-7.3/core/src/main/scala/scalaz/MonadState.scala.shtml\",\"WARC-Payload-Digest\":\"sha1:2KBYHFTHC42Q63LKKLOIWSG6334ISNE7\",\"WARC-Block-Digest\":\"sha1:U4MD3WL3OD26RXFUT3VZ5M7AKES6D2PK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103516990.28_warc_CC-MAIN-20220628111602-20220628141602-00628.warc.gz\"}"}