Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ foo.inside { |v| v.upcase! } #=> Some("BAR")
for value in foo
puts value #=> bar
end

# Thread an option through multiple methods
Option(" 1 ").thread(:strip, :to_i, :next).get #=> 2
Option(" 1 ").thread(:strip, :to_i, :next).get_or_else { "else" } #=> else
```

## Build Status
Expand Down
9 changes: 9 additions & 0 deletions lib/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def each(&blk)
nil
end

def thread(*funcs)
return self unless funcs.length > 0
Option(funcs.shift.to_proc.call(get)).thread(*funcs)
end

def or_nil
get
end
Expand Down Expand Up @@ -128,6 +133,10 @@ def or_nil
nil
end

def thread(*funcs)
self
end

def present?
false
end
Expand Down