Skip to content

Commit dbda062

Browse files
committed
'last' is better returning an optional
1 parent 3c223d1 commit dbda062

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/common.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
179179
if (try extras.doesFolderExist(null, pv)) {
180180
return pv;
181181
}
182-
const file_name = try u.last(try u.split(options.alloc, d.path, "/"));
182+
const file_name = u.last(try u.split(options.alloc, d.path, "/")).?;
183183
if (d.version.len > 0) {
184184
if (try extras.doesFolderExist(null, pv)) {
185185
return pv;

src/util/funcs.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ pub fn list_remove(alloc: std.mem.Allocator, input: []string, search: string) ![
7979
return list.toOwnedSlice();
8080
}
8181

82-
pub fn last(in: []string) !string {
83-
if (in.len == 0) {
84-
return error.EmptyArray;
85-
}
82+
pub fn last(in: []string) ?string {
83+
if (in.len == 0) return null;
8684
return in[in.len - 1];
8785
}
8886

0 commit comments

Comments
 (0)