1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 19:19:53 +00:00

Merge pull request #719 from uvtc/patch-2

Clarify docs on take and drop functions
This commit is contained in:
Calvin Rose 2021-07-25 14:10:01 -05:00 committed by GitHub
commit f6b7cb9c49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1027,7 +1027,7 @@
ret)
(defn take
"Take first n elements in an indexed type. Returns new indexed instance."
"Take the first n elements of an indexed or bytes type. Returns a new tuple or string, respectively."
[n ind]
(def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice))
@ -1038,7 +1038,7 @@
(f ind 0 end))
(defn take-until
"Same as (take-while (complement pred) ind)."
"Same as `(take-while (complement pred) ind)`."
[pred ind]
(def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice))
@ -1048,13 +1048,14 @@
(f ind 0 end))
(defn take-while
`Given a predicate, take only elements from an indexed type that satisfy
the predicate, and abort on first failure. Returns a new array.`
`Given a predicate, take only elements from an indexed or bytes type that satisfy
the predicate, and abort on first failure. Returns a new tuple or string, respectively.`
[pred ind]
(take-until (complement pred) ind))
(defn drop
"Drop first n elements in an indexed type. Returns new indexed instance."
``Drop the first n elements in an indexed or bytes type. Returns a new tuple or string
instance, respectively.``
[n ind]
(def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice))
@ -1065,7 +1066,7 @@
(f ind start -1))
(defn drop-until
"Same as (drop-while (complement pred) ind)."
"Same as `(drop-while (complement pred) ind)`."
[pred ind]
(def use-str (bytes? ind))
(def f (if use-str string/slice tuple/slice))
@ -1075,8 +1076,8 @@
(f ind start))
(defn drop-while
`Given a predicate, remove elements from an indexed type that satisfy
the predicate, and abort on first failure. Returns a new array.`
`Given a predicate, remove elements from an indexed or bytes type that satisfy
the predicate, and abort on first failure. Returns a new tuple or string, respectively.`
[pred ind]
(drop-until (complement pred) ind))