An interesting case of the spurious space syndrome: you're comparing Aaa
with Aaa
(with two spaces around the string).
\documentclass{book}
\usepackage{xparse}
\usepackage{ifthen}
\ExplSyntaxOn
\newcommand\caseswitch[2]{
\str_case_e:nn{#1}{#2}
}
\ExplSyntaxOff
\newcommand\mycommand[1]{% <--- HERE
\caseswitch{#1}{
{A}{Aaa}
{B}{Bbb}
}% <--- HERE
}
\begin{document}
% expected "Function is A :)" but got "Function is B :("
\ifthenelse{\equal{\mycommand{A}}{Aaa}}{Function is A :)}{Function is B :(}
% another version - does not work too
\caseswitch{\mycommand{A}}{{Aaa}{Function is A :)}{Bbb}{Function is B :(}}
\end{document}

I'd use the simpler
\ExplSyntaxOn
\cs_set_eq:NN \caseswitch \str_case_e:nn
\ExplSyntaxOff
and also the reimplementation of \ifthenelse
I proposed elsewhere on the site (see the link for examples of use).
\documentclass{book}
\ExplSyntaxOn
%%% Expandable reimplementation of \ifthenelse
\NewExpandableDocumentCommand{\xifthenelse}{mmm}
{
\bool_if:nTF { #1 } { #2 } { #3 }
}
\cs_new_eq:NN \numtest \int_compare_p:n
\cs_new_eq:NN \oddtest \int_if_odd_p:n
\cs_new_eq:NN \fptest \fp_compare_p:n
\cs_new_eq:NN \dimtest \dim_compare_p:n
\cs_new_eq:NN \deftest \cs_if_exist_p:N
\cs_new_eq:NN \namedeftest \cs_if_exist_p:c
\cs_new_eq:NN \eqdeftest \token_if_eq_meaning_p:NN
\cs_new_eq:NN \streqtest \str_if_eq_p:ee
\cs_new_eq:NN \emptytest \tl_if_empty_p:n
\cs_new_eq:NN \blanktest \tl_if_blank_p:n
\cs_new_eq:NN \boolean \legacy_if_p:n
\cs_new:Npn \modetest #1
{
\str_case:nnF { #1 }
{
{h}{\mode_if_horizontal_p:}
{v}{\mode_if_vertical_p:}
{m}{\mode_if_math_p:}
{i}{\mode_if_inner_p:}
}
{\c_false_bool}
}
\cs_new:Npn \enginetest #1
{
\str_case:nnF { #1 }
{
{luatex}{\sys_if_engine_luatex_p:}
{pdftex}{\sys_if_engine_pdftex_p:}
{ptex}{\sys_if_engine_ptex_p:}
{uptex}{\sys_if_engine_uptex_p:}
{xetex}{\sys_if_engine_xetex_p:}
}
{\c_false_bool}
}
% a utility command
\cs_set_eq:NN \caseswitch \str_case_e:nn
\ExplSyntaxOff
\newcommand\mycommand[1]{%
\caseswitch{#1}{
{A}{Aaa}
{B}{Bbb}
}%
}
\begin{document}
% expected "Function is A :)" but got "Function is B :("
\xifthenelse{\streqtest{\mycommand{A}}{Aaa}}{Function is A :)}{Function is B :(}
% another version - does not work too
\caseswitch{\mycommand{A}}{{Aaa}{Function is A :)}{Bbb}{Function is B :(}}
\end{document}
\ifthenelse
when, as you show,expl3
provides far better control constructs. What is the use case here?\tl_show:x{\mycommand{A}}
,\cs_generate_variant:Nn \tl_analysis_show:n{x} \tl_analysis_show:x{\mycommand{A}}
which will print out the blank spaces.