1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-25 22:53:16 +00:00

Clarify docs on take and drop functions

Pass in indexed and bytes, return tuples and strings, respectively.
This commit is contained in:
John Gabriele 2021-07-24 18:44:49 -04:00 committed by GitHub
parent 160dd830a0
commit 76acbf9bb6
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))