Skip to content

Commit 74003bc

Browse files
committed
Merge pull request #9 from purescript/unsafe-init
Add unsafe version of `init`
2 parents 7eb1337 + e8b5687 commit 74003bc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110

111111
head :: forall a. [a] -> a
112112

113+
init :: forall a. [a] -> [a]
114+
113115
last :: forall a. [a] -> a
114116

115117
tail :: forall a. [a] -> [a]

src/Data/Array/Unsafe.purs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Data.Array.Unsafe where
22

33
import Prelude.Unsafe
4-
import Data.Array (length)
4+
import Data.Maybe.Unsafe
5+
import qualified Data.Array as A
56

67
head :: forall a. [a] -> a
78
head (x : _) = x
@@ -10,4 +11,7 @@ tail :: forall a. [a] -> [a]
1011
tail (_ : xs) = xs
1112

1213
last :: forall a. [a] -> a
13-
last xs = unsafeIndex xs (length xs - 1)
14+
last xs = unsafeIndex xs (A.length xs - 1)
15+
16+
init :: forall a. [a] -> [a]
17+
init = fromJust <<< A.init

0 commit comments

Comments
 (0)