The following are appendices from Optics By Example, a comprehensive guide to optics from beginner to advanced! If you like the content below, there's plenty more where that came from; pick up the book!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs2.{Chunk, Stream, Pull} | |
import cats.collections.Heap | |
import cats.implicits._ | |
object SortMerge { | |
def sortMerge[F[_], A: Ordering](streams: List[Stream[F, A]]): Stream[F, A] = { | |
implicit val ord: cats.Order[Stream.StepLeg[F, A]] = | |
new cats.Order[Stream.StepLeg[F, A]] { | |
val ordA = implicitly[Ordering[A]] |
- Generated by code-examples-manager release 2.4.8-SNAPSHOT
- 656 published examples
- akka-actors-hello-world.sc : Simple akka hello world example
- akka-capitalize-and-print.sc : dump capitalized string coming from stdin using streams
- akka-http-client-json-stream.sc : Fully asynchronous http client call with json streamed response using akka-http will work in all cases, even with chunked responses !
- akka-http-client-json-with-proxy.sc : Fully asynchronous http client call with json response using akka-http will work in all cases, even with chunked responses, this example add automatic http proxy support.
- [akka-http-client-json.sc](https:/
- purity is a syntactical property of programs, more precisely defined as referential transparency: replacing an expression for its bound value doesn't change meaning (precise definition)
- side effects are things that break referential transparency (precise definition)
- There's no direct connection between the concepts of IO, State and so on, and side effects. Traditionally, these things are side effectful (break referential transparency), but you can have abstractions that are pure (don't break ref.trans.)
- Due to the above, the term purely functional programming is not an oxymoron, it makes perfect sense.
- In haskell style pure FP, type constructors and algebras are used to represent "things that would otherwise traditionally be side effects (break ref.trans.)". We call these F[_]s effects or computational contexts for brevity. You can see for yourself how this cannot be a precise definition (especially because they could also have kind higher than * -> *, even though most famous a
I have some data which has adjacent entries that I want to group together and perform actions on.
I know roughly that fs2.Pull
can be used to "step" through a stream and do more complicated
logic than the built in combinators allow. I don't know how to write one though!
In the end we should have something like
def combineAdjacent[F[_], A](
shouldCombine: (A, A) => Boolean,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- roll.hs a dice rolling shell utility | |
-- David Castellà 'kaste' <[email protected]> | |
import Data.List.Split | |
import Data.List | |
import Data.Char | |
import System.Random | |
import Control.Monad | |
import Control.Arrow | |
import Options.Applicative |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In https://github.com/ekmett/lens/wiki/Derivation, we see some types for | |
composition of compositions: (.).(.), (.).(.).(.), and so on. Let's prove that | |
the type of (.).(.) is (a -> b) -> (c -> d -> a) -> c -> d -> b, as stated in | |
the site. We'll stick with prefix notation, meaning that we want the type of | |
(.)(.)(.). | |
Recall the type of composition. This should be intuitive: | |
(.) :: (b -> c) -> (a -> b) -> a -> c [1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Backup image tags to text file. | |
# $ docker images --format "{{.Repository}}:{{.Tag}} {{.ID}}" > img_id.txt | |
# | |
# 2. Execute clean-docker-for-mac script | |
# $ bash clean-docker-for-mac.sh $(docker images --format "{{.ID}}" | xargs) | |
# | |
# source: https://gist.github.com/MrTrustor/e690ba75cefe844086f5e7da909b35ce#file-clean-docker-for-mac-sh | |
# | |
# 3. Execute this script to restore tags from text file. |