Skip to content

Commit a5c44b1

Browse files
committed
Rename module and add a new test
1 parent 9cb64eb commit a5c44b1

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module Data.Lens.Prism.Partial
2-
( unsafeViewPrism, (^?!)
1+
module Data.Lens.Fold.Partial
2+
( unsafeView, (^?!)
33
, unsafeIndexedFold, (^@?!)
44
)
55
where
@@ -14,23 +14,18 @@ import Data.Tuple(Tuple(..))
1414
import Data.Newtype (unwrap)
1515
import Partial.Unsafe (unsafeCrashWith)
1616

17-
unsafeViewPrism :: forall s t a b. Partial => s -> Fold (First a) s t a b -> a
18-
unsafeViewPrism s l = fromMaybe' (crash "unsafeViewPrism: Empty fold") $ previewOn s l
19-
20-
infixl 8 unsafeViewPrism as ^?!
17+
unsafeView :: forall s t a b. Partial => s -> Fold (First a) s t a b -> a
18+
unsafeView s l = fromMaybe' (\_ -> unsafeCrashWith "unsafeView: Empty fold") $ previewOn s l
2119

20+
infixl 8 unsafeView as ^?!
2221

2322
unsafeIndexedFold
2423
:: forall i s t a b. Partial
2524
=> s
26-
-> IndexedFold ((First (Tuple i a))) i s t a b
27-
-> (Tuple i a)
28-
unsafeIndexedFold s l = fromMaybe' (crash "unsafeIndexedFold: empty Fold")
25+
-> IndexedFold (First (Tuple i a)) i s t a b
26+
-> Tuple i a
27+
unsafeIndexedFold s l = fromMaybe' (\_ -> unsafeCrashWith "unsafeIndexedFold: empty Fold")
2928
$ unwrap
3029
$ ifoldMapOf l (\i a -> First $ Just (Tuple i a)) s
3130

3231
infixl 8 unsafeIndexedFold as ^@?!
33-
34-
35-
crash :: forall a. String -> Unit -> a
36-
crash msg _ = unsafeCrashWith msg

test/Main.purs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ import Data.Lens.Index (ix)
77
import Data.Lens.Setter (iover)
88
import Data.Lens.Lens (ilens, IndexedLens, cloneIndexedLens)
99
import Data.Lens.Fold ((^?))
10-
import Data.Lens.Prism.Partial ((^?!))
10+
import Data.Lens.Fold.Partial ((^?!), (^@?!))
1111
import Data.Lens.Zoom (Traversal, Traversal', Lens, Lens', zoom)
1212
import Data.Tuple (Tuple(..))
1313
import Data.Maybe (Maybe(..))
1414
import Data.Either (Either(..))
15-
import Partial.Unsafe (unsafePartial)
16-
1715
import Control.Monad.Eff (Eff)
1816
import Control.Monad.Eff.Console (CONSOLE, logShow)
1917
import Control.Monad.State (evalState, get)
20-
18+
import Partial.Unsafe (unsafePartial)
2119

2220
-- Traversing an array nested within a record
2321
foo :: forall a b r. Lens { foo :: a | r } { foo :: b | r } a b
@@ -34,7 +32,6 @@ doc = { foo: Just { bar: [ "Hello", " ", "World" ]} }
3432
bars :: forall a b. Traversal (Foo a) (Foo b) a b
3533
bars = foo <<< _Just <<< bar <<< traversed
3634

37-
3835
-- Get the index of a deeply nested record
3936
type BarRec = { foo :: Array (Either { bar :: Array Int } String) }
4037
data Bar = Bar BarRec
@@ -51,8 +48,6 @@ _0Justbar = _Bar <<< foo <<< ix 0
5148
_1bars :: Traversal' Bar Int
5249
_1bars = _0Justbar <<< _Left <<< bar <<< ix 1
5350

54-
55-
5651
-- Tests state using zoom
5752
stateTest :: Tuple Int String
5853
stateTest = evalState go (Tuple 4 ["Foo", "Bar"]) where
@@ -70,5 +65,6 @@ main = do
7065
logShow $ view bars doc
7166
logShow $ doc2 ^? _1bars
7267
logShow $ unsafePartial $ doc2 ^?! _1bars
68+
logShow $ unsafePartial $ Tuple 0 1 ^@?! i_2
7369
logShow stateTest
7470
logShow cloneTest

0 commit comments

Comments
 (0)