Created
September 22, 2020 21:34
-
-
Save Ch4s3/ed487f82b792aa93e2acf3d273ceb97d to your computer and use it in GitHub Desktop.
Revisions
-
Ch4s3 created this gist
Sep 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ defmodule Testing do """ You can pipe straight into a case Kernel.<<>>, the special form for binary pattern matching can be used in a case match to split up incoming binaries, like this imaginary |~ delimited protocol. "fiexd_size_header|~some message" You can also pipe into an anonymous function using |> ().() Kernel.& begins the capture and &1 captures the piped arg """ def pipes(input) do input |> case do <<_header::binary-size(17), "|~", rest::binary>> -> rest _ -> raise "Invalid" end |> (&{:ok, &1}).() end end """ iex > Testing.pipes("fiexd_size_header|~some message") {:ok, "some message"} """