Map content inside a nested structure
Mapping that will preserve the element type.
Altering can be used to simplify argument and result types
-- module User.Map exposing (onHead)
import Map
type alias User =
{ name : String, ... }
type Name
= Name
name : Altering String nameAlterTag -> Altering User ( Name, nameAlterTag )
name =
Typed.mapToWrap Name (\f user -> { user | name = user.name |> f })This applies to records, types without any type variables or mapping some of many equal-typed elements
Create a uniquely tagged Mapping for a given function a -> b.
Returns what comes in without changing anything
"please edit"
|> Map.with Map.identity
--> "please edit"Transform elements
as shown in a given Mapping with a given function
import Typed
type Book
= Book
book : Mapping { book : { sales : Int } } Book { sales : Int }
book =
Typed.tag Book .book
type Sales
= Sales
sales : Mapping { sales : Int } Sales Int
sales =
Typed.tag Sales .sales
{ book = { sales = 0 } }
|> Map.with (book |> Map.over sales)
--> 0Apply the given change
import Typed
[ 'h', 'i' ]
|> Map.with (Typed.tag { whatever = () } String.fromList)
--> "hi"
TypedchangeTo create, combine
unmappedtomappedTo "nest"
Mappingstyped-valuehas some powerful helpers:There's nothing more to it
Use [
Alter] ifunmappedandmappedtypes are the same