Last active
August 4, 2020 15:29
-
-
Save Ebmtranceboy/74addbd1bbf3cb1eb6d70113b7262cbd to your computer and use it in GitHub Desktop.
Sum + String lenses
This file contains 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
module Main where | |
import Prelude | |
import Concur.Core (Widget) | |
import Concur.React (HTML) | |
import Concur.React.DOM (text, div', br') as D | |
import Concur.React.Run (runWidgetInDom) | |
import Effect (Effect) | |
import Data.Lens (Prism', prism', prism, _Just) | |
import Data.Lens.Fold (preview) | |
import Data.Lens.Prism (review, is, isn't) | |
import Data.Maybe (Maybe(..)) | |
import Color (Color, white) | |
import Data.Either (Either(..)) | |
import Data.Int (fromString) | |
newtype Percent = Percent Number | |
data Point = Point Number Number | |
data Fill | |
= Solid Color | |
| LinearGradient Color Color Percent | |
| RadialGradient Color Color Point | |
| NoFill | |
instance showFill :: Show Fill where | |
show (Solid c) = "Solid " <> show c | |
show _ = "some filling" | |
_solidFill' :: Prism' Fill Color | |
_solidFill' = prism' Solid case _ of | |
Solid color -> Just color | |
_ -> Nothing | |
_solidFill :: Prism' Fill Color | |
_solidFill = prism Solid case _ of | |
Solid color -> Right color | |
other -> Left other | |
_intSource :: Prism' String String | |
_intSource = | |
prism' identity focuser | |
where | |
focuser s = case (fromString s) of | |
Just _ -> Just s | |
Nothing -> Nothing | |
exerciseWidget :: forall a. Widget HTML a | |
exerciseWidget = | |
D.div' $ (pure <<< (_ <> D.br')) =<< | |
[ D.text $ show $ preview _solidFill' $ Solid white | |
, D.text $ show $ preview _solidFill $ Solid white | |
, D.text $ show $ review _solidFill' white | |
, D.text $ show $ (is _solidFill' (Solid white) :: Boolean) | |
, D.text $ show $ (isn't _solidFill' NoFill :: Boolean) | |
, D.text $ show $ preview (_Just <<< _solidFill') | |
$ Just $ Solid white | |
, D.text $ show $ preview _intSource "134" | |
, D.text $ show $ preview _intSource "a134" | |
] | |
main :: Effect Unit | |
main = do | |
runWidgetInDom "main" exerciseWidget | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment