Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
36 lines (23 loc) · 855 Bytes

File metadata and controls

36 lines (23 loc) · 855 Bytes
Copy raw file
Download raw file
Outline
Edit and raw actions

using

Context managers for Carp. An experiment.

Installation

You can include using in your project like this:

(load "git@github.com:carpentry-org/using@0.0.3")

Usage

using relies on the interface close, which will take in a resource of some kind, clean it up, and return the result of the expression.

If that function is defined, you can do things like that:

(println*
  &(using (Result.unsafe-from-success (File.open "example")) f
    &(File.read-all &f)))

The file that was opened will be automatically closed once the scope is exited.

So, to reiterate: all you need to work with using is to have a function close that works on your type! It’s like manual borrow-checking for resource things! Nifty, eh?

And if you need to support multiple forms, using-do is your friend!


Have fun!

Morty Proxy This is a proxified and sanitized view of the page, visit original site.