on master help sign in
Merge pull request #457 from obsidiansystems/ts-route-maybe

Add route convenience function

commitcad23bb33762b4a2b7e67f0e97539efdf640d4a2 authorElliot Cameron <3noch@users.noreply.github.com> dateWed 15 Jan 2020, 14:06 (7 years ago) parent04d9aae74b1914
2 files changed+12−4
ChangeLog.md+4 lib/route/src/Obelisk/Route.hs+8−4
ChangeLog.md+4
@@ -2,6 +2,10 @@
22
33This project's release branch is `master`. This log is written from the perspective of the release branch: when changes hit `master`, they are considered released, and the date should reflect that release.
44
5+## Unreleased
6+
7+* Add `Obelisk.Route.(?/)`, a convenience function for constructing routes nested in `Maybe`. ([#457](https://github.com/obsidiansystems/obelisk/pull/457))
8+
59## v0.4.0.0 - 2020-01-10
610
711* Bump reflex-platform which, notably, bumps nixpkgs to 19.09. ([#585](https://github.com/obsidiansystems/obelisk/pull/585))
lib/route/src/Obelisk/Route.hs+8−4
@@ -20,10 +20,11 @@
2020{-# LANGUAGE ViewPatterns #-}
2121module Obelisk.Route
2222 ( R
23− , pattern (:/)
2423 , (:.)
25− , pattern (:.)
24+ , (?/)
2625 , hoistR
26+ , pattern (:.)
27+ , pattern (:/)
2728 , PageName
2829 , PathQuery
2930 , Encoder
@@ -194,11 +195,14 @@ import Data.Aeson (FromJSON, ToJSON)
194195
195196type R f = DSum f Identity --TODO: Better name
196197
197−{-# COMPLETE (:/) #-}
198−infixr 5 :/
199198pattern (:/) :: f a -> a -> R f
200199pattern a :/ b = a :=> Identity b
201200
201+-- | Like '(:/)' but adds a 'Just' wrapper around the right-hand side.
202+(?/) :: f (Maybe a) -> a -> R f
203+r ?/ a = r :/ Just a
204+infixr 5 ?/
205+
202206mapSome :: (forall a. f a -> g a) -> Some f -> Some g
203207mapSome f (Some a) = Some $ f a
204208