A Prism is a tool which optionally converts elements of type A into elements of type B and back.
string2IntPrism : Prism String Int
string2IntPrism =
Prism (String.toInt >> Result.toMaybe) toString
string2IntPrism.getOption "17896" == Just 17896
string2IntPrism.getOption "1a896" == Nothing
string2IntPrism.reverseGet 1626767 = "1626767"Checks if value of type A has matching element of type 'B'
Monocle.Prism.isMatching string2IntPrism "abc" == False
Monocle.Prism.isMatching string2IntPrism "123" == TrueModifies given function (b -> b) to be (a -> a) using Prism a b
fx i = i * 2
modified = Monocle.Prism.modify string2IntPrism fx
modified "22" == "44"
modified "abc" == "abc"Modifies given function (b -> b) to be (a -> Maybe a) using Prism a b
fx i = i * 2
modified = Monocle.Prism.modify string2IntPrism fx
modified "22" == Just "44"
modified "abc" == NothingComposes Prism a b with Prism b c and returns Prism a c
prism = Monocle.Prism.compose string2FloatPrism float2IntPrism
prism.getOption "22" == Just 22
prism.getOption "22.2" == Nothing
prism.getOption "22a" == Nothing
prism.getOption "abc" == NothingComposes Prism a b with Iso b c and returns Prism a c
iso = Iso ((*) 10) ((//) 10)
prism = Monocle.Prism.composeIso string2IntPrism iso
prism.getOption "22" == Just 220
prism.getOption "22.2" == Nothing
prism.getOption "22a" == Nothing
prism.getOption "abc" == NothingCasts Iso a b to Prism a b
In order to create a
Prismwe need to supply two functions:getOptionandreverseGet