Repository: casey/just
File: src/thunk.rs (Rust)

Code before:
      | Self::BinaryPlus { name, .. }
      | Self::Ternary { name, .. } => name,
    }
  }

  pub(crate) fn resolve(
    name: Name<'src>,
    mut arguments: Vec<Expression<'src>>,
  ) -> CompileResult<'src, Thunk<'src>> {
    crate::function::get(name.lexeme()).map_or(
      Err(name.error(CompileErrorKind::UnknownFunction {
        function: name.lexeme(),
      })),
      |function| match (function, arguments.len()) {
        (Function::Nullary(function), 0) => Ok(Thunk::Nullary { function, name }),
        (Function::Unary(function), 1) => Ok(Thunk::Unary {
          function,
          arg: Box::new(arguments.pop().unwrap()),
          name,
        }),
        (Function::UnaryOpt(function), 1..=2) => {
          let a = Box::new(arguments.remove(0));
          let opt_b = match arguments.pop() {
            Some(value) => Box::new(Some(value)),
            None => Box::new(None),
          };
          Ok(Thunk::UnaryOpt {
            function,
            args: (a, opt_b),
            name,
          })
        }
        (Function::Binary(function), 2) => {
          let b = Box::new(arguments.pop().unwrap());
          let a = Box::new(arguments.pop().unwrap());
          Ok(Thunk::Binary {
            function,
            args: [a, b],
            name,
          })
        }
        (Function::BinaryPlus(function), 2..=usize::MAX) => {
          let rest: Vec<Expression> = arguments.drain(2..).collect();
          let b = Box::new(arguments.pop().unwrap());
          let a = Box::new(arguments.pop().unwrap());
          Ok(Thunk::BinaryPlus {
            function,
            args: ([a, b], rest),
            name,
          })
        }

Review comment (suggestion):
`remove(0)` to grab from the front of the list, then a `pop` on the last element, happy to hear a prettier way 😅 

Code after:
      | Self::BinaryPlus { name, .. }
      | Self::Ternary { name, .. } => name,
    }
  }

  pub(crate) fn resolve(
    name: Name<'src>,
    mut arguments: Vec<Expression<'src>>,
  ) -> CompileResult<'src, Thunk<'src>> {
    crate::function::get(name.lexeme()).map_or(
      Err(name.error(CompileErrorKind::UnknownFunction {
        function: name.lexeme(),
      })),
      |function| match (function, arguments.len()) {
        (Function::Nullary(function), 0) => Ok(Thunk::Nullary { function, name }),
        (Function::Unary(function), 1) => Ok(Thunk::Unary {
          function,
          arg: Box::new(arguments.pop().unwrap()),
          name,
        }),
        (Function::UnaryOpt(function), 1..=2) => {
          let a = Box::new(arguments.remove(0));
          let b = match arguments.pop() {
            Some(value) => Box::new(Some(value)),
            None => Box::new(None),
          };
          Ok(Thunk::UnaryOpt {
            function,
            args: (a, b),
            name,
          })
        }
        (Function::Binary(function), 2) => {
          let b = Box::new(arguments.pop().unwrap());
          let a = Box::new(arguments.pop().unwrap());
          Ok(Thunk::Binary {
            function,
            args: [a, b],
            name,
          })
        }
        (Function::BinaryPlus(function), 2..=usize::MAX) => {
          let rest = arguments.drain(2..).collect();
          let b = Box::new(arguments.pop().unwrap());
          let a = Box::new(arguments.pop().unwrap());
          Ok(Thunk::BinaryPlus {
            function,
            args: ([a, b], rest),
            name,
          })
        }