Packages

Elixir-native LangChain, LangGraph, and DeepAgents for traceable LLM apps: OTP workflows, tools, memory, human-in-the-loop, streaming, custom clients/adapters, minimal deps, and WeaveScope tracing.

Current section

Files

Jump to
beam_weaver lib beam_weaver filesystem edit.ex
Raw

lib/beam_weaver/filesystem/edit.ex

defmodule BeamWeaver.Filesystem.Edit do
@moduledoc false
alias BeamWeaver.Filesystem.Utils
def replacement(content, old, new, replace_all?) when is_binary(content) do
occurrences = Utils.count_occurrences(content, old)
cond do
occurrences == 0 ->
{:error, :not_found}
replace_all? ->
{:ok, occurrences, String.replace(content, old, new)}
occurrences == 1 ->
{:ok, occurrences, String.replace(content, old, new, global: false)}
true ->
{:error, "multiple occurrences"}
end
end
end